ZOJ - 1074 (DP之最大子矩阵O(N^3))

题目链接

题意:给出一个N表示N阶方正,随后N行每行N列数字表示矩阵中每个格子的数值,问这个矩阵的最大子矩阵价值是多少?

题解:数据比较小,直接O(N^3)过即可.

代码如下:

#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
const int maxn = 1e4 + 500;
int maxsub(int a[], int n){  //求一行的最大连续子序列的值O(n)
	int i, max = 0, b = 0;
	for (i = 0; i 0)
			b += a[i];
		else
			b = a[i];
		if (b > max)
			max = b;
	}
	return max;
}
int main(){
	int n, i, j, k, maxsubrec, maxsubarr;
	int dp[101][101], arr[101];
	while (cin >> n){
		for (i = 0; i> dp[i][j];
		maxsubrec = 0;
		//最大子矩阵O(n^3)
		for (i = 0; i maxsubrec) maxsubrec = maxsubarr;
			}
		}
		cout << maxsubrec << endl;
	}
}

 

你可能感兴趣的:(DP)