Gril @ 2022-04-21 18:47:08
#include<bits/stdc++.h>
#define INF 0x7fffffff
#define F(i,a,b) for(int i = (a);i <= (b);i++)
using namespace std;
int n,res = -INF;
int a[123][123];
void deal(int len,int* ys){ //计算最大连续子序列和函数
if(len <= 0)return;
int maxx= ys[1];
int f[123] = {0}; //最大连续子序列和数组
F(i,1,len){
f[i] = max(f[i-1]+ys[i],ys[i]);
maxx = max(f[i],maxx);
}
res = max(maxx,res); //获取结果
}
int main()
{
cin >> n;
F(i,1,n)F(j,1,n)cin >> a[i][j];
F(i,1,n){
int ys[123] = {0}; //保存压缩数组的数组
F(j,i,n){
F(k,1,n){
ys[k] = ys[k] + a[j][k]; //压缩数组
deal(n,ys);
}
}
}
cout << res;
return 0;
}
by Gril @ 2022-04-21 18:47:30
呜
by Gril @ 2022-04-21 21:20:00
找到问题了...我那个deal函数放错位置了...