Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

贴个模板,要用的拿去用啊

Posted by iluoer at 2016-11-04 10:55:19 on Problem 1276
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator