lraM416 @ 2024-07-24 11:14:27
暴力dp但是hack第一个没过。
#include<bits/stdc++.h>
using namespace std;
int dp[200005],n,l,r,a[200005],s=-20220517,t;
signed main(){
cin>>n>>l>>r;
for(int i=0;i<=n;i++) cin>>a[i],dp[i]=-20220517;
dp[0]=0;
for(int i=0;i<=n;i++)
for(int j=i+l;j<=i+r;j++)
if(j>n) break;
else dp[j]=max(dp[j],dp[i]+a[j]),s=max(s,dp[j]);
cout<<s;
return 0;
}
by Dream__Sky @ 2024-07-24 12:46:21
In:6 2 2 0 1 -1 1 -1 1 -1
Out:-3
by Dream__Sky @ 2024-07-24 12:47:05
@lraM416 自己调去
by Dream__Sky @ 2024-07-24 12:47:55
@lraM416 祝你今年AK NOIP
by lraM416 @ 2024-07-24 12:48:36
@Dream__Sky 我又不参加
by Dream__Sky @ 2024-07-24 12:53:11
@lraM416 666,那祝你AK CSP-J/S
by Dream__Sky @ 2024-07-24 12:54:04
#include<bits/stdc++.h>
using namespace std;
int dp[200005],n,l,r,a[200005],s=-20220517,t;
signed main(){
cin>>n>>l>>r;
for(int i=0;i<=n;i++) cin>>a[i],dp[i]=-20220517;
dp[0]=0;
for(int i=0;i<=n;i++)
for(int j=i+l;j<=i+r;j++)
if(j>n) {
s=max(s,dp[i]);
break;
}
else dp[j]=max(dp[j],dp[i]+a[j]);
cout<<s;
return 0;
}
这是调好的代码,问题在你不能每次跳都更新,要到跳出去的那不在更新,你是gt吗
by lraM416 @ 2024-07-24 13:26:07
@Dream__Sky gt
by Dream__Sky @ 2024-07-24 13:26:27
@lraM416 666