codefroces 33C Wonderful Randomized Sum DP
来源:互联网 发布:linux招聘 编辑:程序博客网 时间:2024/05/21 10:20
题意:在一个数字序列中,可以进行无数字的两种操作,即找出前缀,和后缀,并对这个序列乘以-1,求在可以进行这种操作的情况下,序列和的最大值
做法:怎么说呢,具体看程序吧,一开始少考虑了留出一段不进行操作的情况
#include <iostream>#include <cstdio>#include <cstring>#define LMT 100003using namespace std;int pre[LMT],down[LMT],a[LMT],zhen[LMT],fu[LMT];int main(){ int n,ans; bool yes=0; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",&a[i]); if(a[i]<0) { fu[i]=fu[i-1]+a[i]; zhen[i]=zhen[i-1]; } else { zhen[i]=zhen[i-1]+a[i]; fu[i]=fu[i-1]; } if(zhen[i]+fu[i]>-zhen[i]-fu[i]) pre[i]=zhen[i]+fu[i]; else pre[i]=-zhen[i]-fu[i]; if(pre[i]<a[i]+pre[i-1])pre[i]=a[i]+pre[i-1];//不操作 } memset(zhen,0,sizeof(zhen)); memset(fu,0,sizeof(fu)); for(int i=n;i>=1;i--) { if(a[i]>0) { zhen[i]=zhen[i+1]+a[i]; fu[i]=fu[i+1]; } else { zhen[i]=zhen[i+1]; fu[i]=fu[i+1]+a[i]; } if(zhen[i]+fu[i]>-zhen[i]-fu[i]) down[i]=zhen[i]+fu[i]; else down[i]=-zhen[i]-fu[i]; if(down[i]<down[i+1]+a[i])down[i]=down[i+1]+a[i];//不操作 } for(int i=0;i<=n;i++) if(0==yes||ans<pre[i]+down[i+1]) { ans=pre[i]+down[i+1]; yes=1; } printf("%d\n",ans); return 0;}
- codefroces 33C Wonderful Randomized Sum DP
- #33 C. Wonderful Randomized Sum ( 思维 )
- Wonderful Randomized Sum
- 【Codefroces 490 C Hacking Cypher】+ dp
- codefroces 486C Hack it! 数位dp+二分
- codefroces 482C Game with Strings (概率dp神题)
- Hrbust 2210 A Wonderful Concert【Dp】水题
- 【Codefroces 717 C. Potions Homework】
- CodeFroces 412.C Success Rate
- CodeFroces 412.C Success Rate
- codefroces 425E Sereja and Sets (dp)
- 【XSY2332】Randomized Binary Search Tree 概率DP FFT
- Codefroces 279 div2 C. Hacking Cypher
- CodeFroces # 285 DIV2 C. Misha and Forest
- Codefroces 32C (简单模拟+数学)
- codefroces 723c Polycarp at the Radio
- Codefroces 750C New Year and Rating
- codefroces 791C Bear and Different Names
- 如何定义TS流的空数据包
- Windows server 2008 r2 如何开启Win7的Aero效果
- ContentProvider初步
- 一些经典排序算法的实现(C++实现)
- 排序之希尔排序
- codefroces 33C Wonderful Randomized Sum DP
- iframe加事件
- 浅谈RSTP的快速收敛机制
- python网络编程小例子
- 终端不再繁琐 游戏亦可联网
- Java如何等待子线程执行结束
- DLL HOOK 技术与 Stuxent
- 对象文件格式分析工具: objdump, nm,ar
- 关于给Winform的ListView控件添加右键菜单的问题