BZOJ 1668 馅饼里的财富

时间:2023-12-19 11:59:02

RT.

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m,tab[][],dp[][],ans=;
int main()
{
scanf("%d%d",&n,&m);
for (int i=;i<=n;i++)
for (int j=;j<=m;j++)
scanf("%d",&tab[i][j]);
for (int j=;j<=m;j++)
for (int i=;i<=n;i++)
{
if (i>j) continue;
dp[i][j]=dp[i][j-];
if (i-) dp[i][j]=max(dp[i][j],dp[i-][j-]);
if (i+<=n) dp[i][j]=max(dp[i][j],dp[i+][j-]);
dp[i][j]+=tab[i][j];
}
printf("%d\n",dp[n][m]);
return ;
}