这样做超时了~~
查看原帖
这样做超时了~~
535447
Radia楼主2021/7/7 20:06
#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;
}
2021/7/7 20:06
加载中...