1 solutions
-
0
#include<bits/stdc++.h> using namespace std; const int N=1010; typedef long long LL; int n,m; int w[N][N]; LL f[N][N][2]; int main() { cin>>n>>m; for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { cin>>w[i][j]; } } memset(f,0xcf,sizeof f); f[1][0][0]=0; for(int j=1;j<=m;j++) //枚举所有列 { for(int i=1;i<=n;i++) //从上往下 { f[i][j][0]=max(max(f[i][j-1][0],f[i][j-1][1]),f[i-1][j][0])+w[i][j]; } for(int i=n;i>=1;i--) //从下往上 { f[i][j][1]=max(max(f[i][j-1][0],f[i][j-1][1]),f[i+1][j][1])+w[i][j]; } } cout<<f[n][m][0]; return 0; }
- 1
Information
- ID
- 2796
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 6
- Tags
- # Submissions
- 10
- Accepted
- 4
- Uploaded By