NC16650 采药

\(0-1\)背包裸题

const int N=110,M=1010;
int f[M];
int n,m;

int main()
{
    cin>>m>>n;

    for(int i=1;i<=n;i++)
    {
        int v,w;
        cin>>v>>w;
        for(int j=m;j>=v;j--)
            f[j]=max(f[j],f[j-v]+w);
    }

    cout<<f[m]<<endl;
    //system("pause");
}
原文地址:https://www.cnblogs.com/fxh0707/p/14141044.html