| ||||||||||
| 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 | |||||||||
baneHunterIn Reply To:多重背包 Posted by:1340502116 at 2016-03-09 11:23:47 > #include<cstdio>
> #include<cstring>
> #include<algorithm>
> using namespace std;
> int W,n;
> int w[10005];
> int cnt;
> int dp[100005];
> int main()
> {
> while(scanf("%d%d",&W,&n)!=EOF)
> {
> memset(dp,0,sizeof(dp));
> cnt=0;
> for(int i=0;i<n;i++)
> {
> int b,v;
> scanf("%d%d",&b,&v);
> int e=1;
> while(e<=b)
> {
> w[cnt++]=e*v;
> b-=e;
> e<<=1;
> }
> w[cnt++]=b*v;
> }
>
> for(int i=0;i<cnt;i++)
> for(int j=W;j>=w[i];j--)
> dp[j]=max(dp[j],dp[j-w[i]]+w[i]);
>
> printf("%d\n",dp[W]);
> }
>
> return 0;
> }
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator