POJ1050&HDU1081-To the Max
来源:互联网 发布:微信加人软件 编辑:程序博客网 时间:2024/05/30 04:40
从一个矩阵中寻找和最大的子矩阵,简单的枚举各种情况即可。
数组a表示原矩阵,b表示a中的某几行之和组成的新序列,这样就转换为求新序列的最大连续子序列的和问题了。
在杭电上提交时数据改为多组输入….
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn = 100 + 5;int a[maxn][maxn];int b[maxn];int calc(int n) { int sum,max_sum; sum = max_sum = 0; for (int i = 0; i < n; i++) { sum += b[i]; if (sum > max_sum) { max_sum = sum; } else if (sum < 0) { sum = 0; } } return max_sum;}int main(int argc, char const *argv[]) { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { scanf("%d", &a[i][j]); } } int max_sum = 0; for (int i = 0; i < n; i++) { memset(b, 0, sizeof(b)); for (int j = i; j < n; j++) { for (int k = 0; k < n; k++) { b[k] += a[j][k]; } max_sum = max(max_sum, calc(n)); } } printf("%d\n", max_sum); return 0;}
0 0
- POJ1050&HDU1081-To the Max
- To the max(hdu1081)
- HDU1081--To The Max
- hdu1081-To The Max
- hdu1081-To The Max
- HDU1081 To The Max
- hdu1081 To The Max
- hdu1081 To The Max
- hdu1081 To The Max
- hdu1081 To the Max
- POJ1050 To the Max
- POJ1050 To the Max
- POJ1050 To the Max
- poj1050 to the max
- poj1050 To the Max
- poj1050 To the Max
- POJ1050--To the Max
- POJ1050 To the Max
- js关于select的问题
- java的动态代理机制详解
- windows下的主从复制
- Android中Intent传递对象的两种方法(Serializable,Parcelable)
- ruby 更换gem 源 ,亲测使用,注意字母
- POJ1050&HDU1081-To the Max
- PopupWindow
- 【51Nod】1305 - Pairwise Sum and Divide(思维)
- 算法6:只有五行的Floyd最短路算法
- java集合之map中keySet方法
- Eclipse快捷键 10个最有用的快捷键
- nodejs死亡笔记之cookie和session(宇宙级框架express)
- java基础--13.Regex正则表达式
- Windows下Armadillo配置及测试