POJ 1050 To the Max (简单的线性dp)
来源:互联网 发布:淘宝怎么冲销量 编辑:程序博客网 时间:2024/05/21 09:36
OJ题目:click here~~
题目分析:求子数组之和的最大值,这里是二维的,转化为一维解决。详见《编程之美》P191.
AC_CODE
const int Max_N = 102;const int inf = 1<<30;int PS[Max_N][Max_N];int BC(int a , int c , int m){ return PS[c][m] - PS[a][m] - PS[c][m - 1] + PS[a][m - 1];}int main(){ int n; while(~scanf("%d",&n)) { int i , j , k , num[Max_N][Max_N] , maxinum = -inf; for(i = 1;i <= n;i++) for(j = 1;j <= n;j++) scanf("%d",&num[i][j]); for(i = 0;i <= n;i++) PS[i][0] = 0,PS[0][i] = 0; for(i = 1;i <= n;i++) for(j = 1;j <= n;j++) PS[i][j] = PS[i - 1][j] + PS[i][j - 1] - PS[i - 1][j - 1] + num[i][j]; for(i = 1;i <= n;i++) for(j = i;j <= n;j++){ int start = BC(i , j , n); int all = BC(i , j , n); for(k = n - 1;k >= 1;k--){ if(start < 0) start = 0; start += BC(i , j , k); if(start > all) all = start; } if(all > maxinum) maxinum = all; } cout << maxinum << endl; } return 0;}
0 0
- POJ 1050 To the Max (简单的线性dp)
- zoj 1074 || poj 1050 To the Max(简单DP)
- POJ 1050 To the Max(简单DP)
- POJ 1050 To the Max DP
- POJ 1050 To the Max 经典DP
- POJ 1050 To the Max DP
- poj 1050To the Max dp+暴力
- DP训练 POJ-1050 To the Max
- To the Max - POJ 1050 dp
- POJ 1050 To the Max DP题解
- poj - 1050 - To the Max(dp)
- POJ 1050 - To the Max(DP)
- poj-1050-To the Max【DP】
- POJ-1050-To the Max-dp
- POJ 1050 to the max(dp)
- [DP]poj 1050 To the Max
- poj 1050 To the Max (dp)
- 【POJ 1050】To the Max(dp)
- 金蝶二次开发之C#编写EBOS插件
- 05 RFS自动化之 【Xpath】
- 两种方法清空memcache缓存(转)
- 冒泡排序
- 储存函数结合游标,调度器(备忘)
- POJ 1050 To the Max (简单的线性dp)
- 热敏打印机工作原理
- java中文件操作大全
- Cracking the coding interview--Q20.8
- strcpy和memcpy的区别
- 一个简单的md5算法java实现
- 实现跨路由器共享打印机
- Effective objective-C 理解消息forwarding
- SQL中Group By的使用