标签:
状态转移: dp[i] = min( dp[i], dp[j] + price[i]*(sum[i]-sum[j]+10) )
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 const int N = 101; 6 7 int n; 8 int t; 9 int sum[N], dp[N], price[N]; 10 11 int main() { 12 scanf("%d", &t); 13 while (t--) { 14 scanf("%d", &n); 15 for (int i = 0; i < n; i++) { 16 scanf("%d %d", &sum[i], &price[i]); 17 if (i > 0) { 18 sum[i] += sum[i - 1]; 19 } 20 } 21 22 for (int i = 0; i < n; i++) { 23 dp[i] = (sum[i] + 10) * price[i]; 24 for (int j = 0; j < i; j++) { 25 dp[i] = min(dp[i], (sum[i] - sum[j] + 10) * price[i] + dp[j]); 26 } 27 } 28 29 printf("%d\n", dp[n - 1]); 30 } 31 return 0; 32 }
标签:
原文地址:http://www.cnblogs.com/subrshk/p/4392271.html