总分

哎,现在发现背包问题的伪装方法越来越多了,这题就是一道完全背包,别的不多说了,上代码:

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>

int c[10001],w[10001],f[10001];

int main()
{
    freopen("score.in","r",stdin);
    freopen("score.out","w",stdout);
    int n,m;
    std::cin>>n>>m;
    for(int i = 0;i<m;i++)std::cin>>c[i]>>w[i];
    for(int i = 0;i<m;i++)
        for(int j = w[i];j<=n;j++)
            f[j] = std::max(f[j],f[j-w[i]]+c[i]);
    std::cout<<f[n];
    fclose(stdin);
    fclose(stdout);
    return 0;
}
posted @ 2017-06-13 20:21  leo101  阅读(115)  评论(0编辑  收藏  举报