标签:using hdu ++ amp pig 开始 ret int sed
#include <bits/stdc++.h> #define ll long long using namespace std; const int maxn = 1e5+10; int dp[maxn]; int st,ed; int n; int c[maxn], a[maxn]; int main() { int t; scanf("%d", &t); while(t--) { scanf("%d%d", &st, &ed); int v = ed - st; scanf("%d",&n); for(int i = 1; i <= n; i++) { scanf("%d%d", &c[i], &a[i]); } for(int i = 1;i <= 1e5; i++) dp[i]=1e9; // dp[v]=1e9; dp[0]=0; for(int i = 1; i <= n; i++) { for(int j = a[i]; j <= v; j++) { dp[j] = min(dp[j], dp[j-a[i]] + c[i]); } } if(dp[v]!=1e9) printf("The minimum amount of money in the piggy-bank is %d.\n", dp[v]); else printf("This is impossible.\n"); } return 0; }
标签:using hdu ++ amp pig 开始 ret int sed
原文地址:http://www.cnblogs.com/Superwalker/p/7878363.html