莫名WA,根据01背包改的
查看原帖
莫名WA,根据01背包改的
327281
Phigros_Guest楼主2023/8/31 19:51

无注释,大佬们辛苦了

#include<bits/stdc++.h>
using namespace std;
int t,m,f[101][1001],w[101],c[101];
int main()
{
    cin>>t>>m;
    for(int i=1;i<=m;i++) cin>>w[i]>>c[i];
    for(int i=1;i<=m;i++) for(int j=t;j>=0;j--)
    {
        if(w[i]>j) f[i][j]=f[i-1][j];
        else f[i][j]=max(f[i-1][j],f[i-1][j-w[i]]+c[i]);
    }
    cout<<t-f[m][t];
    return 0;
}
2023/8/31 19:51
加载中...