点我看题目

题意 : 给你一个n*n的矩阵,让你找一个子矩阵要求和最大。

思路 : 这个题都看了好多天了,一直不会做,今天娅楠美女给讲了,要转化成一维的,也就是说每一列存的是前几列的和,也就是说

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

处理后就是:
0  -2  -9  -9
9   11  5   7
-4 -3  -7  -6
-1  7   7   5

 #include <iostream>
#include <stdio.h>
#include <string.h> using namespace std; int sum[][] ;
int main()
{
int n ,m;
while(~scanf("%d",&n))
{
memset(sum,,sizeof(sum)) ;
for(int i = ; i <= n ; i++)
{
for(int j = ; j <= n ; j++)
{
scanf("%d",&m) ;
sum[i][j] = sum[i-][j]+m ;
}
}
int ans = - ;
for(int i = ; i <= n ; i++ )
for(int j = i ; j <= n ; j++)
{
int cnt = ;
for(int k = ; k <= n ; k ++)
{
cnt += sum[j][k]-sum[i-][k] ;
ans = max(cnt,ans) ;
if(cnt < ) cnt = ;
}
}
printf("%d",ans) ;
}
return ;
}

URAL 1146 Maximum Sum & HDU 1081 To The Max (DP)的更多相关文章

  1. URAL 1146 Maximum Sum(最大子矩阵的和 DP)

    Maximum Sum 大意:给你一个n*n的矩阵,求最大的子矩阵的和是多少. 思路:最開始我想的是预处理矩阵,遍历子矩阵的端点,发现复杂度是O(n^4).就不知道该怎么办了.问了一下,是压缩矩阵,转 ...

  2. 最大子矩阵和 URAL 1146 Maximum Sum

    题目传送门 /* 最大子矩阵和:把二维降到一维,即把列压缩:然后看是否满足最大连续子序列: 好像之前做过,没印象了,看来做过的题目要经常看看:) */ #include <cstdio> ...

  3. ural 1146. Maximum Sum

    1146. Maximum Sum Time limit: 0.5 secondMemory limit: 64 MB Given a 2-dimensional array of positive ...

  4. ural 1146. Maximum Sum(动态规划)

    1146. Maximum Sum Time limit: 1.0 second Memory limit: 64 MB Given a 2-dimensional array of positive ...

  5. URAL 1146 Maximum Sum(DP)

    Given a 2-dimensional array of positive and negative integers, find the sub-rectangle with the large ...

  6. URAL 1146 Maximum Sum 最大子矩阵和

    题目:click here #include <bits/stdc++.h> using namespace std; typedef unsigned long long ll; con ...

  7. Timus 1146. Maximum Sum

    1146. Maximum Sum Time limit: 0.5 secondMemory limit: 64 MB Given a 2-dimensional array of positive ...

  8. hdu 1081 To The Max(dp+化二维为一维)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1081 To The Max Time Limit: 2000/1000 MS (Java/Others ...

  9. HDU 1081 To The Max【dp,思维】

    HDU 1081 题意:给定二维矩阵,求数组的子矩阵的元素和最大是多少. 题解:这个相当于求最大连续子序列和的加强版,把一维变成了二维. 先看看一维怎么办的: int getsum() { ; int ...

随机推荐

  1. sql语句聚合等疑难问题收集

    ------------------------------------------------------------------------------------ 除法运算 select 500 ...

  2. OC7_目录操作

    // // main.m // OC7_目录操作 // // Created by zhangxueming on 15/6/19. // Copyright (c) 2015年 zhangxuemi ...

  3. BT之下拉菜单

    <div class="dropdown"> <button class="btn btn-default dropdown-toggle" ...

  4. Ajax和JSON基础

    Ajax (核心是XMLHttpRequest对象) 1.XMLHttpRequest对象: request=new XMLHttpRequest()  支持Firefox opera Safari  ...

  5. spring3.2以后的cglib的jar包问题

    关于cglib的jar包官方的文档上有这么一段话 Note For this dynamic subclassing to work, the class that the Spring contai ...

  6. cplusplus解析

    经常在头文件包含代码里面看到如下代码 #ifndef MAC_API_H #define MAC_API_H #ifdef __cplusplus extern "C"{ #end ...

  7. fltk_hello world

    int main(int argc, char *argv[]) { #define WINDOW_BG FL_BLACK #define WINDOW_WIDTH 640 #define WINDO ...

  8. js 执行效率

    循环 在JavaScript中,我们可以使用for(;;),while(),for(in)三种循环,这三种循环中for(in)的效率极差,因为他需要查询散列键,只要可以就应该尽量少用.for(;;)和 ...

  9. JQuery 判断某个属性是否存在 hasAttr

    $(".fengye a").each(function () { if (typeof($(this).attr("href")) != "unde ...

  10. 【SQLite】使用replace替换字段中的字符

    使用replace替换字段中的字符 如:替换production表中的specification字段中的两个空格为一个空格: update production set specification = ...