求助0分
查看原帖
求助0分
1022472
C_Boa楼主2024/10/20 15:30

记忆化搜索,全WA

#include<bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;
int n,m,mem[105][105],ans;
struct node{
	int value;
	int time;
}a[105];
int dfs(int p,int t){
	if(mem[p][t]!=-1){
		return mem[p][t];
	}
	if(p==m+1){
		return mem[p][t]=0;
	} 
	int d1,d2=-INF;
	d1=dfs(p+1,t);
	if(t>=a[p].time){
		d2=(p+1,t-a[p].time)+a[p].value;
	}	
	return mem[p][t]=max(d1,d2);
}
signed main(){
	cin>>n>>m;
	memset(mem,-1,sizeof(mem));
	for(int i=1;i<=m;i++){
		cin>>a[i].time>>a[i].value;
	}
	cout<<dfs(1,n);
	return 0;
}
2024/10/20 15:30
加载中...