//状态转移方程: F[i] = min{f[k] + (a[k+1]+………+a[i]+10} * p[i]} #include <iostream> #define MAXN 105 using namespace std; int dp[MAXN]; int n[MAXN]; int p[MAXN]; int main() { //freopen("acm.acm","r",stdin); int test; int c; int sum; int tem; int i; int j; int k; int min; int cur; cin>>test; while(test --) { memset(dp,0,sizeof(dp)); cin>>c; for(i = 0; i < c; ++ i) { cin>>n[i]; cin>>p[i]; } sum = 0; dp[0] = (n[0]+10)*p[0]; sum += n[0]; for(i = 1; i < c; ++ i) { sum += n[i]; cur = sum; min = 123456789; tem = (cur+10)*p[i]; if(tem < min) { min = tem; } for(k = 0; k < i; ++ k) { cur -= n[k]; tem = dp[k] + (cur+10)*p[i]; if(tem < min) { min = tem; } } dp[i] = min; } cout<<dp[c-1]<<endl; } }
关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。
技术网站地址: vmfor.com