标签:des style color io os ar for strong sp
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 26675 | Accepted: 9419 |
Description
Input
Output
Sample Input
735 3 4 125 6 5 3 350 633 4 500 30 6 100 1 5 0 1 735 0 0 3 10 100 10 50 10 10
Sample Output
735 630 0 0
多重背包。。。。。,第一次写。
打个模板过了。
AC代码例如以下:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int dp[100005];
int g[15],z[15];
int v;
void ZOpack(int a)
{
int i;
for(i=v;i>=a;i--)
dp[i]=max(dp[i],dp[i-a]+a);
}
void WQpack(int a)
{
int i;
for(i=a;i<=v;i++)
dp[i]=max(dp[i],dp[i-a]+a);
}
void W(int gg,int zz)
{
if(gg*zz>v)
WQpack(zz);
else{
int k=1;
while(k<gg)
{
ZOpack(k*zz);
gg-=k;
k<<=1;
}
ZOpack(gg*zz);
}
}
int main()
{
int n;
int i,j;
while(~scanf("%d%d",&v,&n))
{
memset(dp,0,sizeof dp);
for(i=1;i<=n;i++)
scanf("%d%d",&g[i],&z[i]);
for(i=1;i<=n;i++)
W(g[i],z[i]);
printf("%d\n",dp[v]);
}
return 0;
}
标签:des style color io os ar for strong sp
原文地址:http://www.cnblogs.com/mengfanrong/p/4009026.html