Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
贴个c++代码#include <iostream> using namespace std; const int INF = 0x70123456; const int MAX_N = 105; int need[MAX_N], price[MAX_N]; int dp[MAX_N]; int _min(int a, int b); int main() { int T, c; scanf("%d", &T); while (T--) { scanf("%d", &c); for (int i = 1; i <= c; i++) { scanf("%d%d", need + i, price + i); dp[i] = INF; } for (int i = 1; i <= c; i++) { int s = 10; for (int j = i; j; j--) { s += need[j]; dp[i] = _min(dp[i], dp[j - 1] + s * price[i]); } } printf("%d\n", dp[c]); } return 0; } int _min(int a, int b) { return a < b ? a : b; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator