POJ 1050 To the Max
来源:互联网 发布:电子打鼓软件下载 编辑:程序博客网 时间:2024/05/18 01:19
枚举 + dp, 化二维为一维, 第一次将2-n行分别加到第一行,第二次分别将3-n行加到第二行,再分别对单行求区间最大值。
#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int MAXN = 105;int n, temp[MAXN], a[MAXN][MAXN];inline int arrayMax(int *arr){int max = 0, dp = 0;for (int i = 0; i < n; i++)if (dp < 0)dp = arr[i];else{dp += arr[i];max = dp > max ? dp : max;}return max;}int main(){scanf("%d", &n);for (int i = 0; i < n; i++)for (int j = 0; j < n; j++)scanf("%d", &a[i][j]);int maxAll = 0, maxOne = 0;for (int i = 0; i < n; i++){memset(temp, 0, sizeof(temp));for (int j = i; j < n; j++){for (int k = 0; k < n; k++)temp[k] += a[j][k];maxOne = arrayMax(temp);maxAll = maxOne > maxAll ? maxOne : maxAll;}}printf("%d\n", maxAll);}
0 0
- POJ 1050 To the Max
- poj 1050 To the Max
- POJ 1050 To the Max
- poj 1050 To the Max
- Poj 1050 To the Max
- POJ 1050 To the Max
- POJ 1050 To the Max
- POJ 1050 To the Max
- poj 1050 To the Max
- poj 1050 To the Max
- Poj 1050 To the Max
- POJ 1050 To the Max
- poj 1050 to the max
- POJ 1050 To the Max
- poj 1050 to the max
- poj-1050- To the Max
- POJ-1050-To the Max
- POJ 1050 To the Max
- 记录——《C Primer Plus (第五版)》第十章编程练习第二题
- TCP/IP详解 卷1 笔记 第13章 IGMP: internet组管理协议
- hdu 1175 连连看问题
- hdu 4353
- 楼道声光控工作原理
- POJ 1050 To the Max
- 关于jquery 如何判断checkbox 是否选中
- 【剑指offer】-从尾到头打印链表
- LeetCode Delete Node in a Linked List 链表
- 记项目中的一次错误之RecyclerView
- 记录——《C Primer Plus (第五版)》第十章编程练习第三题
- bzoj1621【Usaco2008 Open】Roads Around The Farm
- 安卓中webview与javascript的交互
- linux常用命令chmod,chown,chgrp