| ||||||||||
| 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 | |||||||||
贴个模板,要用的拿去用啊#include <cstdio>
#include <string.h>
#include <algorithm>
const int maxn = 1e5+10;
int dp[maxn];
int cot[maxn],l,r;
int main()
{
int m,n;
while(~scanf("%d%d",&m,&n)){
int len = 0;
memset(dp,0,sizeof(dp));
memset(cot,0,sizeof(cot));
for(int i=0;i<n;i++){
scanf("%d%d",&l,&r);
for(int k=1;k<=l;k<<=1){
cot[len++] = k*r;
l-=k;
}
if(l>0){
cot[len++] = l*r;
}
}
for(int i=0;i<len;i++){
for(int j=m;j>=cot[i];j--){
dp[j] = std::max(dp[j],dp[j-cot[i]]+cot[i]);
}
}
printf("%d\n",dp[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