求助
查看原帖
求助
735123
_Ray楼主2022/7/19 23:10

用的动态规划。输入样例2的时候,不知道为什么,输出的是-2,觉得在max部分写得不太对,自己改不出来。

#include<bits/stdc++.h>
using namespace std;
int x[1005][1005];
int main(){
	int a,b;
	cin>>a>>b;
	for(int i=1;i<=a;i++){
		for(int j=1;j<=b;j++){
			cin>>x[i][j];
		}
	}
	for(int i=1;i<=a;i++){
		for(int j=1;j<=b;j++){
			x[i][j]+= max(x[i][j-1],max(x[i-1][j],x[i+1][j]));
		}
	}
	cout<<x[a][b];
}
2022/7/19 23:10
加载中...