社区讨论

这样做超时了~~

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

讨论操作

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

当前回复
2 条
当前快照
1 份
快照标识符
@loc78fv3
此快照首次捕获于
2023/10/30 09:06
2 年前
此快照最后确认于
2023/11/04 18:27
2 年前
查看原帖
CPP
#include <bits/stdc++.h>
using namespace std;
int t, m;
struct S{
	int t;
	int v;
}s[105];
int f(int time, int i = 0){
	if(i == m)
		return 0;
	int n1 = f(time, i+1), n2 = n1;
	if(time-s[i].t >= 0)
		n2 = f(time-s[i].t, i+1)+s[i].v;
	return n1 > n2? n1: n2;
}
int main(){
	cin >> t >> m;
	for(int i = 0; i < m; i++)
		cin >> s[i].t >> s[i].v;
	cout << f(t);
	return 0;
}

回复

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

正在加载回复...