Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
这题挺简单的,完全背包,注意钱数÷1000#include <cstdio> #include <cstring> using namespace std; int max(int a,int b) { return (a>b)?a:b; } int read() { int x=0,f=1;char c=getchar(); while (c<'0' || c>'9'){if (c=='-')f=-1;c=getchar();} while (c>='0'&&c<='9'){x=(x<<1)+(x<<3)+c-48;c=getchar();} return x*f; } const int MAXN=10000; const int MAXM=50000; int m,v,n; int f[MAXM]; int a[MAXN],b[MAXN]; int main() { int cas;cas=read(); while (cas--) { m=read();v=read();n=read(); for (int i=1;i<=n;i++) a[i]=read(),b[i]=read(); int ans=0,most=m; for (int k=1;k<=v;k++) { memset(f,0,sizeof(f)); for (int i=1;i<=n;i++) { for (int j=(a[i]/1000);j<=(most/1000);j++) f[j]=max(f[j],f[j-(a[i]/1000)]+b[i]); } ans+=f[(most/1000)];most+=f[(most/1000)]; } printf("%d\n",ans+m); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator