标签:des style blog http color os io strong for
Description
Value | Annual interest |
4000 3000 |
400 250 |
Input
Output
Sample Input
1 10000 4 2 4000 400 3000 250
Sample Output
14050
算法思考:
很有意思的一道完全背包问题,只要想到是背包问题,基本就能解决了!
#include <stdio.h> #include <string.h> #define N 50006 int dp[N], w[N], p[N]; int max(int a, int b) { return a > b ? a : b; } int main() { int t; int aa, yy, d; int n, v, i, k; scanf("%d", &t); while(t--) { scanf("%d %d", &aa, &yy); scanf("%d", &d); for(i=1; i<=d; i++) { scanf("%d %d", &p[i], &w[i] );//花费 收入 p[i] = p[i]/1000; } n = d;//种类 while(yy--) { memset(dp, 0, sizeof(dp)); v = aa/1000; for(i=1; i<=n; i++) { for(k=0; k<=v; k++) { if( k>=p[i] ) dp[k] = max (dp[k], dp[k-p[i]]+w[i] ); } } aa = aa+dp[v]; } printf("%d\n", aa ); } }
标签:des style blog http color os io strong for
原文地址:http://www.cnblogs.com/yspworld/p/3938767.html