To The Max

To The Max

时间限制(普通/Java):3000MS/10000MS          运行内存限制:65536KByte
总提交:11            测试通过:8

描述

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 N2 integers separated by whitespace (spaces and newlines). These are the N2 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 the sum of the maximal sub-rectangle.

样例输入

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

8 0 -2

样例输出

15

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int a[110][110];
int b[10000];
int main()
{
    int n,m,i,j,k;
    while(scanf("%d",&n)!=EOF)
    {
        int max=-100;
        for(i=0; i<n; i++)
        {
            for(j=0; j<n; j++)
            {
                scanf("%d",&a[i][j]);
            }
        }
        for(i=0; i<n; i++)
        {

            memset(b,0,sizeof(b));
            for(j=i; j<n; j++)
            {
                int t=0;
                for(k=0; k<n; k++)
                {
                    b[k]+=a[j][k];
                    //printf("%d ",b[k]);
                    if(t<=0)
                    {
                        t=b[k];
                    }
                    else
                        t+=b[k];
                    if(t>max)
                        max=t;
                }
            }
        }
        printf("%d\n",max);
    }
    return 0;
}


"Unable to locate the Javac Compiler"是一个错误消息,表明在编译Java代码时找不到Javac编译器。这个问题通常出现在两种情况下:一是没有正确安装Java JDK,二是没有设置正确的JAVA_HOME环境变量。 引用和引用中的错误消息提示了可能的原因和解决方法。首先,确保你已经安装了Java JDK,并且版本是1.4或以上。你可以通过检查Java安装目录下是否有tools.jar文件来确认是否安装了完整的JDK。 如果已经正确安装了JDK,那么问题可能是由于没有设置正确的JAVA_HOME环境变量导致的。你可以通过设置JAVA_HOME环境变量来告诉系统JDK的安装路径。具体设置方法取决于你使用的操作系统。在Windows系统中,你可以按照以下步骤设置环境变量: 1. 打开控制面板,并选择系统和安全。 2. 点击系统,然后点击高级系统设置。 3. 在系统属性窗口中,点击环境变量。 4. 在用户变量或系统变量中,找到名为JAVA_HOME的变量(如果没有则创建)。 5. 设置JAVA_HOME的值为JDK的安装路径,比如C:\Program Files\Java\jdk1.8.0_111。 6. 确认设置并关闭窗口。 在Mac或Linux系统中,你可以编辑.bash_profile或.bashrc文件,并在其中添加以下行: ``` export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home export PATH=$JAVA_HOME/bin:$PATH ``` 保存文件并退出,然后执行"source .bash_profile"或"source .bashrc"命令使环境变量生效。 一旦你安装了JDK并设置了JAVA_HOME环境变量,你应该能够解决"Unable to locate the Javac Compiler"的问题。如果问题仍然存在,你可以尝试重新安装JDK或查找其他解决方法。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Unable to locate the Javac Compiler in 错误的解决办法之一](https://blog.csdn.net/wangming1473/article/details/72781679)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [[ERROR] Unable to locate the Javac Compiler in: [ERROR] /Library/Internet Plug-Ins/JavaAppletPlugi](https://blog.csdn.net/nonolive/article/details/113505370)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值