poj2593
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |code--------------------------------------------------------------------------------------------------+ |001| /***************************************************************\ |002| *Author: 小呼 |003| *Created Time: Tue 06 Jul 2010 02:49:20 PM CST |004| *File Name: a.cpp |005| *Description:动态规划。Max_L[i]表示A[1...i]中最大的连续和,同理 |006| *Max_R[i]是指A[i...n]中最大的连续和 |007| \***************************************************************/ |008| //*======================*Head File*======================*\\ |009| |010| #include<iostream> |011| #include<stdio.h> |012| #include<stdlib.h> |013| #include<string.h> |014| /*----------------------*Global Variable*----------------------*/ |015| |016| //*=====================*Main Program*=====================*// |017| using namespace std; |018| int A[100001],n,Max_L[100001],Max_R[100001]; |019| int main(){ |020| . while ( scanf ( "%d" ,&n)!=EOF&&n){ |021| . . for ( int i=1;i<=n;++i) |022| . . scanf ( "%d" ,A+i); |023| . . int _max=-9999999,temp=-9999999; |024| . . for ( int i=1;i<n;++i){ |025| . . . if (temp>=0) |026| . . . temp+=A[i]; |027| . . . else |028| . . . . temp=A[i]; |029| . . . _max=_max>temp?_max:temp; |030| . . . Max_L[i]=_max; |031| . . } |032| . . _max=temp=-999999; |033| . . for ( int i=n;i>1;--i){ |034| . . . if (temp>0) |035| . . . temp+=A[i]; |036| . . . else |037| . . . temp=A[i]; |038| . . . _max=_max>temp?_max:temp; |039| . . . Max_R[i]=_max; |040| . . } |041| . . int res=-999999; |042| . . for ( int i=1;i<n;++i){ |043| . . . res=(res>Max_L[i]+Max_R[i+1]?res:Max_L[i]+Max_R[i+1]); |044| . . } |045| . . printf ( "%d\n" ,res); |046| . } |047| . return 0; |048| } end+--------------------------------------------------------------------------------------------------+ |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】凌霞软件回馈社区,携手博客园推出1Panel与Halo联合会员
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从零实现富文本编辑器#3-基于Delta的线性数据结构模型
· 记一次 .NET某旅行社酒店管理系统 卡死分析
· 长文讲解 MCP 和案例实战
· Hangfire Redis 实现秒级定时任务,使用 CQRS 实现动态执行代码
· Android编译时动态插入代码原理与实践
· 使用TypeScript开发微信小程序(云开发)-入门篇
· 没几个人需要了解的JDK知识,我却花了3天时间研究
· 定时任务稳定性解决方案-healthchecks监控系统
· 在SqlSugar的开发框架中增加对低代码EAV模型(实体-属性-值)的WebAPI实现支持
· .NET Core中的配置Configuration实战