URAL 1146 Maximum Sum & HDU 1081 To The Max (DP)
题意 : 给你一个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)的更多相关文章
- URAL 1146 Maximum Sum(最大子矩阵的和 DP)
Maximum Sum 大意:给你一个n*n的矩阵,求最大的子矩阵的和是多少. 思路:最開始我想的是预处理矩阵,遍历子矩阵的端点,发现复杂度是O(n^4).就不知道该怎么办了.问了一下,是压缩矩阵,转 ...
- 最大子矩阵和 URAL 1146 Maximum Sum
题目传送门 /* 最大子矩阵和:把二维降到一维,即把列压缩:然后看是否满足最大连续子序列: 好像之前做过,没印象了,看来做过的题目要经常看看:) */ #include <cstdio> ...
- ural 1146. Maximum Sum
1146. Maximum Sum Time limit: 0.5 secondMemory limit: 64 MB Given a 2-dimensional array of positive ...
- ural 1146. Maximum Sum(动态规划)
1146. Maximum Sum Time limit: 1.0 second Memory limit: 64 MB Given a 2-dimensional array of positive ...
- URAL 1146 Maximum Sum(DP)
Given a 2-dimensional array of positive and negative integers, find the sub-rectangle with the large ...
- URAL 1146 Maximum Sum 最大子矩阵和
题目:click here #include <bits/stdc++.h> using namespace std; typedef unsigned long long ll; con ...
- Timus 1146. Maximum Sum
1146. Maximum Sum Time limit: 0.5 secondMemory limit: 64 MB Given a 2-dimensional array of positive ...
- 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 ...
- HDU 1081 To The Max【dp,思维】
HDU 1081 题意:给定二维矩阵,求数组的子矩阵的元素和最大是多少. 题解:这个相当于求最大连续子序列和的加强版,把一维变成了二维. 先看看一维怎么办的: int getsum() { ; int ...
随机推荐
- JAVA输入/输出系统中的其他流学习笔记
一.字节数组流 字节数组流类能够操作内存中的字节数组,它的数据是一个字节数组.字节数组流类本身适配器设计模式,它把字节数组类型转为流类型使得程序能够对字节数组进行读写操作. 1.ByteArrayIn ...
- iOS开发——model类模板(过滤null和ID)
说明:model类模板已默认过滤null值,附加特殊情况的关键字ID名的冲突(需手动去掉注释代码).MyMessageModel为示例的名字.可以自己随便起. 1.自己创建一个继承与N ...
- using System.Collections.Generic;
public class CommonClass { public static void ShowInt(int iValue) { //typeof(CommonClass) typeof关键字 ...
- OC7_复合类内存管理(setter方法)
// // Person.h // OC7_复合类内存管理(setter方法) // // Created by zhangxueming on 15/6/18. // Copyright (c) 2 ...
- 在ASP.NET中实现压缩多个文件为.zip文件,实现批量下载功能 (转载并优化处理篇)
转自:http://blog.csdn.net/yanlele424/article/details/6895986 这段时间一直在做一个网站,其中遇到了一个问题,就是在服务器端压缩多个服务器端的文件 ...
- ubuntu配置多个DNS
Ubuntu设置了静态IP地址,设置DNS,打开/etc/resolv.conf cat /etc/resolv.conf# Dynamic resolv.conf(5) file for glibc ...
- Eclipse必须掌握的快捷键
Eclipse快捷键 Ctrl + / 添加//注释.删除//注释 Ctrl + 1 快速修复错误 Ctrl + Shift + f 格式化文档 Shift + Enter Shift + Ctrl ...
- C#源码大汇总
C#高仿QQ2013可在广域网部署聊天系统GG叽叽 动态显示硬盘分区容量饼图 自定义ProgressBar控件高仿Win8进度条 多皮肤精美在线QQ悬浮客服插件 jQuery仿天猫首页多格焦点图片轮播 ...
- c++,C# 转换
//C++中的DLL函数原型为 //extern "C" __declspec(dllexport) bool 方法名一(const char* 变量名1, unsi ...
- spring-cloud-bus
安装rabbitmq 依赖erlang: http://erlang.org/download/otp_win64_18.2.exe