poj1050 动态规划
来源:互联网 发布:汽车 挂件 知乎 编辑:程序博客网 时间:2024/06/05 13:21
题意:给定N*N的矩阵,求最大子矩阵和
算法:动态规划。枚举子矩阵a[i,j],表示从第i行到第j行组成的矩阵,将其每列相加,即可转换为求一维数组的最大连续子段和问题。
设dp[k]表示以元素k结束的最大子段和,那么,dp[k]=max{dp[k-1]+a[k],a[k]}
#include <iostream>#include <string.h>using namespace std;const int SIZE=110;int INF = -127 * SIZE * SIZE;int a[SIZE][SIZE];int main(){int n;cin >> n;for (int i=1; i<=n; i++){for (int j=1; j<=n; j++){cin >> a[i][j];}}int sum[SIZE][SIZE];memset(sum,0,sizeof(sum));int ans = INF ;for (int i=1; i<=n; i++){for (int j=i; j<=n; j++){int dp[SIZE] ;for (int k=1; k<=n; k++){sum[i][k] += a[j][k]; // sum[i][k] = sum[i:j][k] (dp[k-1] > 0)? dp[k] = dp[k-1] + sum[i][k] : dp[k] = sum[i][k]; if (dp[k] > ans){ans = dp[k];}}}}cout << ans << endl;}
0 0
- 动态规划 poj1050
- acm-poj1050(动态规划)
- poj1050 动态规划
- POJ1050简单动态规划:区间DP
- poj1050 To the Max (动态规划)
- POJ1050 To the Max 动态规划
- POJ1050 To the Max 简单动态规划
- poj1050(动态规划+最大子矩阵和)
- 【POJ1050】To the Max (动态规划、最大字串和、最大子矩阵和)||NYOJ44 ||NYOJ104
- 动态规划入门(二)DP 基本思想 具体实现 经典题目 POJ1088 POJ1163 POJ1050
- poj1050 动态规划 求二维数组中子矩阵和的最大值
- POJ1050
- poj1050
- POJ1050
- poj1050
- poj1050
- POJ1050
- poj1050
- 集合问题 动态规划 01背包
- VC++深入详解第一章代码
- Noip2008普及组
- Android Bluetooth模块学习笔记
- Spring项目中cannot resolve file applicationContext.xml错误
- poj1050 动态规划
- Python实现汉诺塔
- 判断链表中是否存在环
- 剑指offer(3):替换空格
- 13(守护进程)
- 解析计算公式,然后生成自己想要的格式
- JavaScript Date.getTime() 函数详解
- 淘宝高可伸缩高性能架构的相关框架介绍
- PopupWindow实现任意位置动画显隐