RT.
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int n,m,tab[105][105],dp[105][105],ans=0; int main() { scanf("%d%d",&n,&m); for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) scanf("%d",&tab[i][j]); for (int j=1;j<=m;j++) for (int i=1;i<=n;i++) { if (i>j) continue; dp[i][j]=dp[i][j-1]; if (i-1) dp[i][j]=max(dp[i][j],dp[i-1][j-1]); if (i+1<=n) dp[i][j]=max(dp[i][j],dp[i+1][j-1]); dp[i][j]+=tab[i][j]; } printf("%d\n",dp[n][m]); return 0; }
时间: 2024-10-26 12:29:18