BCSP2024JR2

阅读程序:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include<iostream>
using namespace std;
int n,m,Max,c;
int a[1000][1000];
int Minn(int x,int y,int z){
    	int res=x;
	    if(res>y) res=y;
	    if(res>z) res=z;
return res;
}
int Square(int x,int y){
	    if(x==1) return a[x][y];
	    if(y==1) return a[x][y];
	    int res=a[x][y]+Minn(Square(x-1,y),Square(x,y-1),Square(x-1,y-1));
	    Max=max(Max,res);
	    if(a[x][y]==0) res=0;
return res;
}
int main (){
    cin >> n >> m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin >> a[i][j];
        }
    }
    Square(n,m); 
	cout << Max;
return 0; 
}
Scroll to Top