[POJ1050]To the Max(最大子矩阵,DP)
2016-06-18 11:00
302 查看
题目链接:http://poj.org/problem?id=1050
发现这个题没有写过题解,现在补上吧,思路挺经典的。
思路就是枚举所有的连续的连续的行,比如1 2 3 4 12 23 34 45 123 234 345...然后把这些行对应列相加缩成一行,之后就是求最大子序列和了。
发现这个题没有写过题解,现在补上吧,思路挺经典的。
思路就是枚举所有的连续的连续的行,比如1 2 3 4 12 23 34 45 123 234 345...然后把这些行对应列相加缩成一行,之后就是求最大子序列和了。
/* ━━━━━┒ギリギリ♂ eye! ┓┏┓┏┓┃キリキリ♂ mind! ┛┗┛┗┛┃\○/ ┓┏┓┏┓┃ / ┛┗┛┗┛┃ノ) ┓┏┓┏┓┃ ┛┗┛┗┛┃ ┓┏┓┏┓┃ ┛┗┛┗┛┃ ┓┏┓┏┓┃ ┛┗┛┗┛┃ ┓┏┓┏┓┃ ┃┃┃┃┃┃ ┻┻┻┻┻┻ */ #include <algorithm> #include <iostream> #include <iomanip> #include <cstring> #include <climits> #include <complex> #include <fstream> #include <cassert> #include <cstdio> #include <bitset> #include <vector> #include <deque> #include <queue> #include <stack> #include <ctime> #include <set> #include <map> #include <cmath> using namespace std; #define fr first #define sc second #define cl clear #define BUG puts("here!!!") #define W(a) while(a--) #define pb(a) push_back(a) #define Rint(a) scanf("%d", &a) #define Rll(a) scanf("%lld", &a) #define Rs(a) scanf("%s", a) #define Cin(a) cin >> a #define FRead() freopen("in", "r", stdin) #define FWrite() freopen("out", "w", stdout) #define Rep(i, len) for(int i = 0; i < (len); i++) #define For(i, a, len) for(int i = (a); i < (len); i++) #define Cls(a) memset((a), 0, sizeof(a)) #define Clr(a, x) memset((a), (x), sizeof(a)) #define Full(a) memset((a), 0x7f7f7f, sizeof(a)) #define lrt rt << 1 #define rrt rt << 1 | 1 #define pi 3.14159265359 #define RT return #define lowbit(x) x & (-x) #define onenum(x) __builtin_popcount(x) typedef long long LL; typedef long double LD; typedef unsigned long long ULL; typedef pair<int, int> pii; typedef pair<string, int> psi; typedef pair<LL, LL> pll; typedef map<string, int> msi; typedef vector<int> vi; typedef vector<LL> vl; typedef vector<vl> vvl; typedef vector<bool> vb; const int maxn = 110; int G[maxn][maxn]; int n; int dp[maxn]; int lss() { int tmp = -0x7f7f7f, ret = -0x7f7f7f; For(i, 1, n+1) { if(tmp > 0) tmp += dp[i]; else tmp = dp[i]; ret = max(tmp, ret); } return ret; } int main() { // FRead(); while(~Rint(n)) { For(i, 1, n+1) For(j, 1, n+1) Rint(G[i][j]); int ret = 0; For(i, 1, n+1) { Cls(dp); For(j, i, n+1) { For(k, 1, n+1) dp[k] += G[j][k]; ret = max(ret, lss()); } } printf("%d\n", ret); } RT 0; }
相关文章推荐
- 包含min函数的栈
- 代理模式
- android中Invalidate和postInvalidate的区别
- C#中Dynamic关键字
- LeetCode-350 Intersection of Two Arrays II
- C++简单多线程事件驱动同步通知到主线程
- 字符编码笔记:ASCII,Unicode和UTF-8
- 函数与类
- Android day8
- 数据结构与算法:二叉树
- MS Chart Control - X轴 项目超9项时 Label显示不完全(已解决)
- 使用quartyz2D画圆,并将其三等分
- (OK)(OK)(All in CLI) Fedora23 + Docker(busybox) + NS3 + MANETs - testing
- 172. Factorial Trailing Zeroes
- mongodb 编译
- ERROR: 1005 Can't create table 'tmp_db' (errno: 13)
- Spark性能调优——扩展篇
- IO-同步,异步,阻塞,非阻塞
- 最小的K个数31
- Spring对jdbc的支持