luogu1353 Running
dp[i][j]表示走i分钟疲劳值为j时的最远距离
然后搞一下就好啦
#include <iostream> #include <cstdio> #include <algorithm> #include <cstdlib> #include <cstring> #include <cmath> #include <vector> #include <stack> #define ll long long #define inf (-1u>>1) using namespace std; inline int read() { int ans=0,f=1; char ch=getchar(); while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();} while(isdigit(ch)){ans=10*ans+ch-'0';ch=getchar();} return ans*f; } int d[20100]; int f[20100][5100]; int main() { int n,m; n=read();m=read(); for(int i=1;i<=n;i++)d[i]=read(); for(int i=1;i<=n;i++) { for(int j=0;j<=m;j++) { if(j>0)f[i][j]=max(f[i][j],f[i-1][j-1]+d[i]); if(i>=j) { f[i][0]=max(f[i-j][j],f[i][0]); f[i][0]=max(f[i-1][0],f[i][0]); } } } cout<<f[n][0]; return 0; }
另:一天10000分钟 这牛怕是叫□-□