社区讨论
10分求调
P1048[NOIP 2005 普及组] 采药参与者 2已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @lttd773w
- 此快照首次捕获于
- 2024/03/16 08:43 2 年前
- 此快照最后确认于
- 2024/03/16 11:07 2 年前
CPP
#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;
}
回复
共 1 条回复,欢迎继续交流。
正在加载回复...