Https://vjudge.net/contest/68966#problem/F
http://blog.csdn.net/libin56842/article/details/9048173
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <string>5#include <algorithm>6#include <cmath>7 #defineINF 0x3f3f3f3f8 using namespacestd;9 Const intmaxn=1e4+Ten;Ten intDP[MAXN]; One intweight[505]; A intmoney[505]; - intMain () - { the intT; -scanf"%d",&T); - while(t--) - { + //memset (Dp,0,sizeof (DP)); - inte,f; +scanf"%d%d",&e,&F); A intv=f-E; at for(intI=0; i<=v;i++) - { -dp[i]=INF; - } -dp[0]=0; - intN; inscanf"%d",&n); - for(intI=1; i<=n;i++) to { +scanf"%d%d",&money[i],&weight[i]); - } the for(intI=1; i<=n;i++) * { $ for(intk=weight[i];k<=v;k++)Panax Notoginseng { -Dp[k]=min (dp[k],dp[k-weight[i]]+money[i]); the } + } A if(dp[v]<INF) the { +printf"The minimum amount of money in the Piggy-bank is%d.\n", Dp[v]); - } $ Else $ { -printf"This is impossible.\n"); - } the - }Wuyi return 0; the}
View Code
"Algorithm Series learning" [Kuangbin you fly] topic 12 basic DP1 F-piggy-bank "complete knapsack problem"