poj 1050 To the Max (简单dp)
题目链接:http://poj.org/problem?id=1050
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std; const int maxn = ;
const int INF = 0x3f3f3f; int dp[maxn];
int sum[maxn][maxn];
int ans; int main()
{
//freopen("E:\\acm\\input.txt","r",stdin);
int N;
cin>>N;
for(int i=;i<=N;i++) sum[][i] = sum[i][] = ;
for(int i=;i<=N;i++)
for(int j=;j<=N;j++){
int a;
scanf("%d",&a);
sum[i][j] = sum[i-][j] + a;
}
ans = -INF;
for(int i=;i<=N;i++)
for(int j=i;j<=N;j++){
memset(dp,,sizeof(dp));
for(int k=;k<=N;k++){
dp[k] = max(,dp[k-]) + sum[j][k] - sum[i][k];
ans = max(dp[k],ans);
}
}
printf("%d\n",ans);
}
//自己的做时候,一直想怎样写dp并表示出状态转移方程,但是就是怎么也想不出来,觉得不好表示。没办法看了别人的想法,马上反应过来。头脑僵化了啊!!!
poj 1050 To the Max (简单dp)的更多相关文章
- poj - 1050 - To the Max(dp)
题意:一个N * N的矩阵,求子矩阵的最大和(N <= 100, -127 <= 矩阵元素 <= 127). 题目链接:http://poj.org/problem?id=1050 ...
- poj 1050 To the Max(线性dp)
题目链接:http://poj.org/problem?id=1050 思路分析: 该题目为经典的最大子矩阵和问题,属于线性dp问题:最大子矩阵为最大连续子段和的推广情况,最大连续子段和为一维问题,而 ...
- POJ 1050 To the Max 枚举+dp
大致题意: 求最大子矩阵和 分析: 一开始想复杂了,推出了一个状态方程:d[i][j]=max(d[i][j-1]+-,d[i-1][j]+-).写着写着发现上式省略的部分记录起来很麻烦. 后来发现n ...
- [poj]1050 To the Max dp
Description Given a two-dimensional array of positive and negative integers, a sub-rectangle is any ...
- POJ 1050 To the Max 最大子矩阵和(二维的最大字段和)
传送门: http://poj.org/problem?id=1050 To the Max Time Limit: 1000MS Memory Limit: 10000K Total Submi ...
- poj 1050 To the Max(最大子矩阵之和)
http://poj.org/problem?id=1050 我们已经知道求最大子段和的dp算法 参考here 也可参考编程之美有关最大子矩阵和部分. 然后将这个扩大到二维就是这道题.顺便说一下,有 ...
- poj 1050 To the Max 最大子矩阵和 经典dp
To the Max Description Given a two-dimensional array of positive and negative integers, a sub-rect ...
- poj 1050 To the Max(最大子矩阵之和,基础DP题)
To the Max Time Limit: 1000MSMemory Limit: 10000K Total Submissions: 38573Accepted: 20350 Descriptio ...
- POJ 1050 To the Max 暴力,基础知识 难度:0
http://poj.org/problem?id=1050 设sum[i][j]为从(1,1)到(i,j)的矩形中所有数字之和 首先处理出sum[i][j],此时左上角为(x1,y1),右下角为(x ...
随机推荐
- c#静态成员和静态类
说起静态类,你可能会联想到实例类.这两者并不难区分,前者(静态类)只在内存中创建一个,而后者(实例类)则是每次实例化后,就会再内存创建一份.今天来简单聊一下静态类的理解. 代码情景: class Pr ...
- C#转Python计划
1.学习python语法,完成python_cookbook上的代码. 目标:熟悉python语法和开发习惯,以及调试方法. 2.学习使用Django框架,完成一个基于Django框架的项目,发布到g ...
- 尝试封装自己的js库
学了js,用过jquery,然后想着让自己在js这一块有更深的提高,就想尝试着封装自己的js库,偶尔就添加自己想到的功能.有参考过其他大牛封装库的方法,不懂的地方也有借鉴过,但代码还是自己想,自己理解 ...
- boost::thread boost库线程
一.boost::thread的创建 1.线程创建方法一: boost::shared_ptr<boost::thread> writeThread_; boost::function0& ...
- c++相关知识回顾
1.typedef typedef用来定义同类型的同义词.如: typedef unsingned int size_t; typedef int ptrdiff_t; typedef T * ite ...
- Git新手入门手册
1.配置email及name git config --global user.email "guxuelong@f-road.com.cn" git config --globa ...
- make xxx Is a directory. Stop.
转自:make xxx Is a directory. Stop. 的原因 make xxx Is a directory. Stop. 的原因 编译内核时候的一个错误提示 make: *** ...
- Codeforces 712C Memory and De-Evolution
Description Memory is now interested in the de-evolution of objects, specifically triangles. He star ...
- 在objc项目中使用常量的最佳实践
在objc项目中使用常量的最佳实践 之前,在在objc项目中使用常量中,使用c的预处理#define来设置常量.比如,可以做个头文件,然后在需要的类文件中import,使用常量. 但这不是最佳实践 ...
- 解决poi导出Excel异常org.openxmlformats.schemas.spreadshe
JAVA报表 POI未捕获到 servlet OUTEXCEL 的其中一个服务方法中抛出的异常.抛出的异常:java.lang.NoClassDefFoundError: org.openxmlfor ...