NOIP T4 n^2 dp 求助
  • 板块学术版
  • 楼主m1kusama
  • 当前回复2
  • 已保存回复2
  • 发布时间2023/11/21 17:54
  • 上次更新2023/11/22 16:56:25
查看原帖
NOIP T4 n^2 dp 求助
538821
m1kusama楼主2023/11/21 17:54
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define ls (now<<1)
#define rs (now<<1|1)
#define P pair<int,int>
#define pb() push_back()
using namespace std;
int n,m,mak,d;
const int N=1e4+10;
P ma[N];
int a[N];
int dp[N][N];//dp[i][k]表示在截止第i天,连续跑步k天的最大能量值 
int ans=-1e9;
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	int c,T,x,y,v;
	cin>>c>>T;
	while(T--){
		cin>>n>>m>>mak>>d;
		memset(a,0,sizeof a);
		for(int i=1;i<=n;i++)ma[i]={-1,0};
		for(int i=1;i<=m;i++){
			cin>>x>>y>>v;
			P add;
			add.first=y,add.second=v;
			ma[x]=add;
		}
		for(int i=0;i<=n;i++)for(int j=0;j<=n;j++)dp[i][j]=0;
		for(int i=1;i<=n;i++){
			for(int k=0;k<=i;k++){
				if(k>mak)continue;
				if(k!=0)dp[i][k]=max(dp[i][k],dp[i-1][k-1]+(k>=ma[x].first and ma[x].first!=-1?ma[x].second:0)-d);
				dp[i][0]=max(dp[i][0],dp[i-1][k]);
			}
		}
		int ans=-1e9;
		for(int j=0;j<=mak;j++){
			ans=max(ans,dp[n][j]);
		}
		cout<<ans<<endl;
	}
	return 0;
}
2023/11/21 17:54
加载中...