标签:
DP.
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int n,m,d[10050],f[10050],dp[20050][505]; int main() { scanf("%d%d",&n,&m); for (int i=1;i<=n;i++) scanf("%d",&d[i]); for (int i=1;i<=n;i++) { dp[i][1]=f[i-1]+d[i];f[i+1]=max(f[i+1],dp[i][1]);f[i+1]=max(f[i+1],f[i]); for (int j=2;j<=m;j++) { dp[i][j]=dp[i-1][j-1]+d[i]; f[i+j]=max(f[i+j],dp[i][j]); } } printf("%d\n",f[n]); return 0; }
标签:
原文地址:http://www.cnblogs.com/ziliuziliu/p/5927295.html