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

题目地址: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
zlxiaonan
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2007-9-29
收藏
得分:0 
以下是引用醉生梦死在2007-11-14 12:29:40的发言:
自己顶一下,测试了不少数据没错啊,为什么一直wa
拜托。。把话说明白点,,“一直wa”是什么意思?
2007-11-14 15:55
醉生梦死
Rank: 1
等 级:新手上路
帖 子:77
专家分:0
注 册:2007-8-21
收藏
得分:0 
回复:(zlxiaonan)以下是引用醉生梦死在2007-11-14 ...
judge it as wrong answer

2007-11-14 18:08
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 
我这里看不了你的链接,把题目贴出来,(估计是E文的,顺便翻译一下)

你用的是DP.

倚天照海花无数,流水高山心自知。
2007-11-14 20:50
醉生梦死
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.014534 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved