POJ 1050 To the max
来源:互联网 发布:js算法题 编辑:程序博客网 时间:2024/06/06 01:43
看了别人的码写出来的,我觉得二维转换成一维的这个思想非常巧妙啊!~~~
#include <cstdio>#include <cstring>#include <iostream>using namespace std;int temp[1000];int one_sum(int *arr, int n) { //求一维子序列最大和 int sum = 0, max = 0; for (int i = 1; i <= n; i++) { sum = (sum > 0) ? (sum + arr[i]) : arr[i]; if (sum > max) max = sum; } return max;}int maxM(int arr[][1000], int n) { int max = arr[1][1]; int sum = 0; for (int i = 1; i <= n; i++) { memset(temp, 0, sizeof(temp)); for (int j = i; j <= n; j++) { for (int k = 1; k <= n; k++) { temp[k] += arr[j][k]; } sum = one_sum(temp, n); if (sum > max) max = sum; } } return max;}int main(void) { int N; int A[1000][1000]; while (~scanf("%d", &N)) { for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { scanf("%d", &A[i][j]); } } printf("%d\n", maxM(A, N)); } return 0;}
阅读全文
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
- Python Unicode与中文处理
- Git服务器安装 windows
- 安卓驱动程序架构
- [模板]
- 数据库连接池之dbcp
- POJ 1050 To the max
- android面试题,各大企业常见的android面试题之五
- JS函数的概念
- Configuration--environments(三-5)
- java 中的单例模式
- 整理:Android客户端面试题集锦
- C语言经典一百例
- MySQL常用内置函数说明
- 快速傅立叶变换(FFT)