easy dp
2016-05-28 21:35
260 查看
1.将一堆正整数分为2组,要求2组的和相差最小。
View Code
//File Name: nod1051.cpp //Author: long //Mail: 736726758@qq.com //Created Time: 2016年05月28日 星期六 21时22分03秒 #include <stdio.h> #include <string.h> #include <algorithm> #include <iostream> #define LL long long using namespace std; const int MAXN = 501; LL b[MAXN],f[MAXN]; int a[MAXN][MAXN]; LL get(int n){ LL ans = 0; f[0] = 0; for(int i=1;i<=n;i++){ f[i] = max(f[i-1],0LL) + b[i]; if(f[i] > ans) ans = f[i]; } return ans; } LL solve(int n,int m){ LL ans = -1; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++) b[j] = 0; for(int j=i;j<=n;j++){ for(int k=1;k<=m;k++) b[k] = b[k] + a[j][k]; LL now = get(m); if(now > ans) ans = now; } } return ans; } int main(){ int n,m; while(~scanf("%d %d",&m,&n)){ bool flag = false; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ scanf("%d",&a[i][j]); if(a[i][j] >= 0) flag = true; } } if(!flag) puts("0"); else printf("%lld\n",solve(n,m)); } return 0; }
View Code
相关文章推荐
- multiset的插入与删除
- WPS中公式标注与公式居中对齐
- RMQ算法
- Uva-227 Puzzle
- 《Python3廖雪峰》datetime转timestamp练习题答案
- 面向对象设计思想20160528
- 《java入门第一季》之tcp协议下的编程实现键盘录入数据不断地往服务器端发送数据案例
- 《java入门第一季》之tcp协议下的编程实现键盘录入数据不断地往服务器端发送数据案例
- 构建支持registry v2的shipyard的镜像
- VirtualBox 虚拟 Ubuntu 的一些感想
- FZU 2168
- Android事件分发总结
- 183. Customers Who Never Order
- Duilib学习笔记《06》— 窗体基类WindowImpBase
- epoll中et+多线程模式中很重要的EPOLL_ONESHOT实验
- Java 实现奇数阶幻方的构造
- c++ primer 第五版 StrBlob类(p404)
- android 优化总结
- 手抄代码1-17
- nyoj 28 大数阶乘