1.HDU 1114 Piggy Bank
一道简单的背包问题
#include <iostream> #include <cstdio> #include <cstring> using namespace std; #define ll long long const int N = 10005; const int INF = 0x3f3f3f3f; int dp[N]; int main() { // freopen("a.in" , "r" , stdin); int T; scanf("%d" , &T); while(T--) { int E , F; scanf("%d%d" , &E , &F); int M = F-E; int n,v,w; scanf("%d" , &n); memset(dp , 0x3f , sizeof(dp)); dp[0]=0; for(int i=0 ; i<n ; i++){ scanf("%d%d" , &v , &w); for(int j=w ; j<=M ; j++){ dp[j] = min(dp[j] , dp[j-w]+v); } } if(dp[M]<INF) printf("The minimum amount of money in the piggy-bank is %d.\n" , dp[M]); else puts("This is impossible."); } return 0; }