0分求助
查看原帖
0分求助
991302
__pyx__楼主2023/8/13 06:52
#include<bits/stdc++.h>
using namespace std;
int dp[110][110];
int m,t,s[110],c[110];
int i,j;
int main()
{
    cin>>t>>m;
    for(i=0;i<m;i++)
        cin>>s[i]>>c[i];
    for(i=0;i<=t;i++)
        if(i>s[0])dp[0][i]=c[0];
    for(i=1;i<=m;i++)
    {
        for(j=1;j<=t;j++)
        {
            if(c[i]>j)dp[i][j]=dp[i-1][j];
            else dp[i][j]=max(dp[i-1][j],dp[i-1][j-s[i]]+c[i]);
        }
    }
    cout<<dp[m][t];
    return 0;
}
2023/8/13 06:52
加载中...