Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1273 Accepted Submission(s): 631
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<string> #include<algorithm> #include<cstdlib> #define INF 100000000 using namespace std; int dp[205],n,x,y,a[205],b[205]; bool check(int mid) { memset(dp,-1,sizeof(dp)); dp[0]=0; for(int i=1;i<=n;i++) { int cntx=min(x,mid/a[i]); if(dp[x]>=y) return true; for(int j=x;j>=0;j--) { for(int k=0;k<=cntx&&(j-k)>=0;k++) { if(dp[j-k]<0) continue; dp[j]=max(dp[j],dp[j-k]+(mid-k*a[i])/b[i]); } } } return dp[x]>=y; } int main() { int tt,cas=1; scanf("%d",&tt); while(tt--) { int ans=0; scanf("%d%d%d",&n,&x,&y); for(int i=1;i<=n;i++) { scanf("%d%d",&a[i],&b[i]); } int l,r; l=0,r=INF; while(l<=r) { int mid; mid=(l+r)>>1; if(check(mid)) { ans=mid; r=mid-1; } else l=mid+1; } printf("Case %d: %d\n",cas++,ans); } return 0; }
原文:http://www.cnblogs.com/water-full/p/4510236.html