hdu 1231 DP
来源:互联网 发布:淘宝美工主图 编辑:程序博客网 时间:2024/06/05 14:07
超级简单的DP 不过那个判断要注意下。。。我开始用sum = -sum(abs(a[i]))来判断一直错。。。。。。
ac代码如下:
#include <iostream>#include <cstdio>#include <cmath>using namespace std;int main(){int K, a[10010], first, pos, end, startfrom, dp[10010], flog;while( scanf( "%d", &K ) && K ){memset( a, 0, sizeof( a ) );memset( dp, 0, sizeof( dp ) );flog = 1;for( int i = 0; i < K; i++ ){scanf( "%d", a + i );if( a[i] >= 0 ){flog = 0;}}if( flog ){cout << 0 << " " << a[0] << " " << a[K-1] << endl;continue;}startfrom = a[0];first = end = pos = 0;dp[0] = a[0];for( int i = 1; i < K; i++ ){if( startfrom + a[i] < a[i] ){startfrom = a[i];pos = i;}else{startfrom += a[i];}if( dp[i-1] < startfrom ){first = pos;end = i;dp[i] = startfrom;}else{dp[i] = dp[i-1];}}cout << dp[K-1] << " " << a[first] << " " << a[end] << endl;}return 0;}
- HDU 1003 && HDU 1231 DP
- hdu 1231 DP水题
- hdu 1231 DP
- hdu dp 1231
- HDU 1231 DP
- dp 入门 hdu 1231
- HDU DP
- DP? HDU
- DP? HDU
- DP? HDU
- 【dp】HDU
- 【dp】HDU
- 【dp】 HDU
- DP? HDU
- HDU 1231 (简单DP问题)
- hdu 1231 最大连续子序列(DP)
- HDU 1231 最大连续子序列 (dp)
- hdu 1231最大连续子序列 【DP】
- host ... is not allowed to connect to this MySql server
- C++设计模式
- 文章格式比较好看的B-Tree的实现讲解的文章
- VMware 虚拟机安装 Mac OS X Mountain Lion 苹果系统
- semaphore信号量
- hdu 1231 DP
- 黑马程序员--代理
- 【Windows】问题:PC机无法共享服务器或pc机?
- CSS hack之特殊符号的应用大全
- 黑马程序员_java网络编程
- FreeRTOS 中断优先级嵌套错误引发HardFault异常解决
- [LDD3速记]_内核的数据类型
- sqlite 用法总结
- C# 基本概念3