社区讨论

求条

P1048[NOIP 2005 普及组] 采药参与者 1已保存回复 0

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
0 条
当前快照
1 份
快照标识符
@m3ye9h59
此快照首次捕获于
2024/11/26 19:49
去年
此快照最后确认于
2024/11/26 19:56
去年
查看原帖
CPP
#include <bits/stdc++.h>
using namespace std;
int T,M;
struct beach{
	int num;
	bool f;
}t[105],w[105];
int g[1005];
int dfs(int x){
	if(x<0) return -1e9;
	if(x==0) return 0;
	if(g[x]!=-1e9) return g[x];
	int maxn=INT_MIN;
	for(int i=1; i<=M; i++){
		if(!t[i].f){
			t[i].f=1;w[i].f=1;
			maxn=max(maxn,dfs(x-t[i].num)+w[i].num);
			t[i].f=0;w[i].f=0;
		}
	}
	if(maxn<0) maxn=0;
	return g[x]=maxn;
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin>>T>>M;
	for(int i=1; i<=T; i++){
		g[i]=-1e9;
	}
	for(int i=1; i<=M; i++){
		cin>>t[i].num>>w[i].num;
	}
	cout<<dfs(T)<<"\n";
	return 0;
} 

回复

0 条回复,欢迎继续交流。

正在加载回复...