zoj1074 TO THE MAX(动态规划)
来源:互联网 发布:网络小精灵粤语 编辑:程序博客网 时间:2024/06/05 10:56
1、问题描述
2、用数组b表示数组a的i~j行对应列元素的和,然后对数组b计算最大字段和,这就将二维动态规划问题转化为一维动态规划的问题。
#include <iostream>#include<cstring>using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */#define N 101int main(int argc, char** argv) { int a[N][N]; int b[N]; int n; int i,j,k; while(cin>>n){ for(int i=0;i<n;i++){ for(int j=0;j<n;j++) cin>>a[i][j]; } int max=-1000; for(int i=0;i<n;i++){ memset(b,0,sizeof(b)); for(j=i;j<n;j++){ int sum=0; for(k=0;k<n;k++){ b[k]+=a[j][k]; if(sum<0)sum=b[k]; if(sum>max)max=sum; } } } cout<<max<<endl; } return 0;}
0 0
- zoj1074 TO THE MAX(动态规划)
- zoj1074 To the Max
- zoj1074 To the Max
- zoj1074 to the max
- ZOJ1074-To the Max(dp)
- zoj1074 To the Max(简单的DP)
- To The Max(动态规划)
- HDOJ题目1081 To The Max(动态规划)
- (动态规划DP算法)To the Max
- HDU 1081 To The Max(动态规划)
- POJ 1050-To the Max (动态规划)
- hdu 1081 To The Max (动态规划)
- To the Max(动态规划DP)
- POJ 1050 To the Max -- 动态规划
- To the Max-动态规划 树状数组
- HDU 1081 To The Max 动态规划
- poj1050 To the Max (动态规划)
- 三维动态规划 To The Max
- 阿里巴巴数据研发工程师面试
- 入职新公司后的一些吐槽
- Maven Tutorial
- 精研技术十数年,我却失业了
- 燕尾定理
- zoj1074 TO THE MAX(动态规划)
- 树的定义
- 分析2个代码片段(数值范围,类型转换相关)
- altium desiner 智能交互布线出现的方法
- 动态规划法—0-1背包问题(二)
- 最长单调递增子序列
- thinkPHP3.0开启trace
- 用Java语言实现对十六进制字符串异或运算
- timer function set and clear out in JavaScript