| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1059 人关注过本帖
标题:我都郁闷了!这道最大子矩阵问题我错拿了
取消只看楼主 加入收藏
醉生梦死
Rank: 1
等 级:新手上路
帖 子:77
专家分:0
注 册:2007-8-21
收藏
 问题点数:0 回复次数:4 
我都郁闷了!这道最大子矩阵问题我错拿了

题目地址:http://acm.jlu.edu.cn/joj/showproblem.php?pid=1092
代码:
#include <iostream>
using namespace std;

int MaxSum(int n,int a[])
{
int sum = 0;
int b = 0;
for (int i = 1;i <= n;i ++)
{
if (b > 0) b += a[i];
else b =a[i];
if (b > sum) sum = b;

}
return sum;
}

int main()
{
int n;
cin >> n; //n边长

int a[n+1][n+1];
for (int i = 1;i <= n;i ++)
for (int j = 1;j <= n;j ++)
cin >> a[i][j];

int sum = 0;
int *b = new int[n+1];
for (int i = 1;i <= n;i ++)
{
for (int k = 1;k <= n;k ++)
b[k] = a[i][k]; 高手指教啊
for (int j = i + 1;j <= n;j ++)
{
for (int k = 1;k <=n;k ++)
b[k] += a[j][k];
int max = MaxSum(n,b);
if (max > sum)
sum = max;
}
}



cout << sum << endl;
}


搜索更多相关主题的帖子: 大子 矩阵 
2007-11-14 10:37
醉生梦死
Rank: 1
等 级:新手上路
帖 子:77
专家分:0
注 册:2007-8-21
收藏
得分:0 
自己顶一下,测试了不少数据没错啊,为什么一直wa

2007-11-14 12:29
醉生梦死
Rank: 1
等 级:新手上路
帖 子:77
专家分:0
注 册:2007-8-21
收藏
得分:0 
回复:(zlxiaonan)以下是引用醉生梦死在2007-11-14 ...
judge it as wrong answer

2007-11-14 18:08
醉生梦死
Rank: 1
等 级:新手上路
帖 子:77
专家分:0
注 册:2007-8-21
收藏
得分:0 
回复:(nuciewth)我这里看不了你的链接[em03],把题目...

题目:

Given a two-dimensional array of positive and negative integers, a sub-rectangle is any contiguous sub-array of size 1 x 1 or greater located within the whole array. The sum of a rectangle is the sum of all the elements in that rectangle. In this problem the sub-rectangle with the largest sum is referred to as the maximal sub-rectangle.

As an example, the maximal sub-rectangle of the array:

0 -2 -7 0
9 2 -6 2
-4 1 -4 1
-1 8 0 -2

is in the lower left corner:

9 2
-4 1
-1 8

and has a sum of 15.

The input consists of an N x N array of integers. The input begins with a single positive integer N on a line by itself, indicating the size of the square two-dimensional array. This is followed by N 2 integers separated by whitespace (spaces and newlines). These are the N 2 integers of the array, presented in row-major order. That is, all numbers in the first row, left to right, then all numbers in the second row, left to right, etc. N may be as large as 100. The numbers in the array will be in the range [-127,127].

Output
Output the sum of the maximal sub-rectangle.
Sample Input
4
0 -2 -7 0 9 2 -6 2
-4 1 -4 1 -1
8 0 -2
Sample Output
15


2007-11-14 21:55
醉生梦死
Rank: 1
等 级:新手上路
帖 子:77
专家分:0
注 册:2007-8-21
收藏
得分:0 

Input:
输入一个n*n的矩阵,矩阵中的元素为整型,输入的第一个数独自占一行,表示n的值,后面是n^2个整数,他们之间用空格或者换行分开
Output:
求这个矩阵的子矩阵,要求这个子矩阵中的元素之和是最大的,并输出最大值


2007-11-14 22:02
快速回复:我都郁闷了!这道最大子矩阵问题我错拿了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019457 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved