琪露诺

题目链接:https://www.luogu.com.cn/problem/P1725

题意:

从0开始 ,每次可以跳到 i+l~ i+r 范围上,求跳到大于n后格子的最大val

思路:

线性dp,考虑dp[i]为以i开头时的最大val,那么答案就是dp[0]

转移:res=max(res,dp[p]) p:i+l ~ i+r

因为一定要跳到最后,所以dp[i]取值是不能保留初始值的,而是从后面挑选最大的上

从后往前枚举,注意初始化都为0

但0~n上的每个格子初值都为a[i]

#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define pb push_back
#define endl "\n"
#define fi first
#define se second
#define int long long
//#pragma GCC optimize(3)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 lll;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const ll llmax=LLONG_MAX;
const int maxn=1e5+5;
const int mod=1e9+7;

void solve(){
	int n,l,r;
	cin>>n>>l>>r;
	vector<int>a(n+1,0);
	for(int i=0;i<=n;i++){
		cin>>a[i];
	}
	int res;
	vector<int>dp(2*n+1,0);
	for(int i=n;i>=0;i--){
		dp[i]=a[i];
		res=-inf;
		for(int p=i+l;p<=i+r;p++){
			res=max(a[i]+dp[p],res);
		}
		dp[i]=res;
	}
	cout<<dp[0]<<endl;
}

signed main()
{
	ios::sync_with_stdio(false),cin.tie(0);
	int T=1;
	
	while(T--){
	solve();
	}
	
	return 0;
}


posted @ 2025-03-06 17:34  Marinaco  阅读(22)  评论(0)    收藏  举报
//雪花飘落效果