#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e3+10;
int n,m;//n为行数,m为列数;
/* 1 2 3 4 5 ... m (j)
1
2
3
4
5
...
n
(i)
*/
long long a[N][N];//a[i][j]:i->行数,j->列数;
long long f[N][N][2];//f[i][j][1/0]:i,j同上,1从下来,0从上来;
/*
转移方程:
1 2 3 4
1 (1,1)(1,2)(1,3)(1,4)
1 -1 3 2
2 (2,1)(2,2)(2,3)(2,4)
2 -1 4 -1
3 (3,1)(3,2)(3,3)(3,4)
-2 2 -3 -1
----------------------
从左:因为左右一样
f[i][j][0]=max(f[i][j-1][0],f[i][j-1][1])+a[i][j];
f[i][j][1]=max(f[i][j-1][0],f[i][j-1][1])+a[i][j];
从上:f[i][j][0]=max(f[i][j][0],f[i-1][j][0]+a[i][j]);
从下:f[i][j][1]=max(f[i][j][1],f[i+1][j][0]+a[i][j]);
*/
int main()
{
sca
[CSP-J2020] 方格取数
于 2022-03-18 20:27:51 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)