2020-12-17cf
今天写少,明天补上
https://codeforc.es/problemset/problem/1197/D
Yet Another Subarray Problem
刚开始有点动态规划的想法,后来去写尺取了,完独自
状态转移挺好推,记得特判1(或者有大佬没有特判。。。。)
#include<iostream> #include<string> #include<queue> #include<string> using namespace std; typedef long long ll; const int maxn = 3e5+111; const ll INF = 1e17; ll list[maxn]; ll n,m,s; ll dp[maxn][22]; ll sum[maxn]; int main() { cin>>n>>m>>s; for(int i=1; i<=n; i++) { cin>>list[i]; } for(int i=0;i<n;i++){ for(int j=0;j<20;j++){ dp[i][j] = -INF; } } ll ans = 0; if(m == 1){ dp[1][0] = list[1] - s; for(int i=1;i<=n;i++){ dp[i+1][0] = max(dp[i][0] + list[i+1] - s ,list[i+1] - s); ans = max(dp[i][0],ans); } cout<<ans<<endl; return 0; } dp[1][1] = list[1] - s; for(int i=1;i<=n;i++){ dp[i][1] = max(dp[i][1],list[i] - s); for(int j=0;j<m;j++){ if(j == 0){ dp[i+1][j+1] = max(dp[i][j] + list[i+1] - s,dp[i+1][j+1]); } else{ dp[i+1][(j+1)%m] = max(dp[i+1][(j+1)%m],dp[i][j] + list[i+1] ); } ans = max(ans,dp[i][j]); } } cout<<ans<<endl; return 0; }
哦对了补上昨天的
寻找真正的热爱