USACO 3.1.2 Score Inflation 题解
【算法】动态规划 【难度】★☆☆☆☆
很经典的完全背包问题。
详见dd的背包九讲
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 /*
2 ID: wsc5001
3 LANG: C
4 TASK: inflate
5 */
6 #include <stdio.h>
7 #include <stdlib.h>
8 int c,v;
9 int s[10000+10];
10 int t[10000+10];
11 int f[10000+10];
12 int bigger(int a,int b)
13 {
14 return a>b?a:b;
15 }
16 int main()
17 {
18 freopen("inflate.in","r",stdin);
19 freopen("inflate.out","w",stdout);
20 scanf("%d%d",&v,&c);
21 int i,j,k,e;
22 for (i=1;i<=c;i++)
23 scanf("%d%d",&s[i],&t[i]);
24 for (i=0;i<=v+1;i++)//初始化
25 f[i]=0;
26 for (i=1;i<=c;i++)
27 for (j=t[i];j<=v;j++)
28 f[j]=bigger(f[j],f[j-t[i]]+s[i]);
29 printf("%d\n",f[v]);
30 //system("pause");
31 fclose(stdin);
32 fclose(stdout);
33 }
wsc500原创,转载请注明出处。请注明 出自http://www.cnblogs.com/loveidea/