10分求调
查看原帖
10分求调
919243
shuyihang楼主2024/3/16 08:42
#include <bits/stdc++.h>
using namespace std;
int T,M;
int t[1001],v[101];
int dp[1001][101];
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>T>>M;
    for(int i=1;i<=M;i++){
    	cin>>t[i]>>v[i];
	}
	for(int i=1;i<=M;i++){
		for(int j=0;j<=T;j++){
			if(j>=t[i]){
				dp[i][j]=max(dp[i-1][j],dp[i-1][j-t[i]]+v[i]);
			}else{
				dp[i][j]=dp[i-1][j];
			}
		}
	}
	cout<<dp[M][T];
	return 0;
}
2024/3/16 08:42
加载中...