[DP]HOJ 1760The jackpot
来源:互联网 发布:photoshop for linux 编辑:程序博客网 时间:2024/05/18 07:23
传送门:The jackpot
The jackpot
Submitted : 5803, Accepted : 1688
As Manuel wants to get rich fast and without too much work, he decided to make a career in gambling. Initially, he plans to study the gains and losses of players, so that, he can identify patterns of consecutive wins and elaborate a win-win strategy. But Manuel, as smart as he thinks he is, does not know how to program computers. So he hired you to write programs that will assist him in elaborating his strategy.
Your first task is to write a program that identifies the maximum possible gain out of a sequence of bets. A bet is an amount of money and is either winning (and this is recorded as a positive value), or losing (and this is recorded as a negative value).
InputThe input set consists of a positive number N <= 10000 , that gives the length of the sequence, followed by N integers. Each bet is an integer greater than 0 and less than 1000.
The input is terminated with N = 0.
OutputFor each given input set, the output will echo a line with the corresponding solution. If the sequence shows no possibility to win money, then the output is the message "Losing streak."
Sample Input512 -4 -10 4 93-2 -1 -20Sample Output
The maximum winning streak is 13.Losing streak.Thanks To
Problem setter: David Deharbe
解题报告:
此题为简单的求最大子段和。状态转移方程:dp[i+1]=arr[i]+max(dp[i],0);代码如下:
#include<iostream>#include<cstring>#include<cstdio>using namespace std;int dp[10005];int main(){ int n,s,ans; while(scanf("%d",&n)==1&&n){ ans=-1; memset(dp,0,sizeof(dp)); for(int i=0;i<n;i++){ scanf("%d",&s); dp[i+1]=s+max(dp[i],0); if(dp[i+1]>ans) ans=dp[i+1]; } if(ans>0) printf("The maximum winning streak is %d.\n",ans); else printf("Losing streak.\n"); } return 0;}
- [DP]HOJ 1760The jackpot
- Hoj 1760 The jackpot
- hoj 1760 The jackpot一维
- UVA 10684 || HOJ 1760 The jackpot
- UVA10684 The jackpot 贪心/dp
- UVA 10684 The jackpot
- UVa:10684 The jackpot
- UVa 10684 - The jackpot
- uva 10670 The jackpot
- TOJ 1782.The jackpot
- uva 10684 The jackpot
- 【UVa】10684 - The jackpot
- hit oj 1760 The jackpot (最大子段和)
- (简单) 状态压缩dp HOJ 2421 Hie with the Pie
- (中等) 状态压缩dp HOJ 2480 The best travel design
- HOJ 1438 The Tower of Babylon(线性DP)
- hoj Score Sequence DP
- hoj Quantum Blasting DP
- Maven教程初级篇02:pom.xml配置初步
- /etc/rc.d/init.d/functions 脚本详解【如何写出像红帽一样NB的启动脚本】
- [多图]美国实习薪水最高的20家科技公司
- java web开发之 spring单元测试
- Maven教程初级篇03: 创建Web应用
- [DP]HOJ 1760The jackpot
- Lambda表达式委托使用
- 给你的AIR程序做个启动画面
- 是你的程序员辛苦还是他们太懒?
- 软件公司的测试人员为什么更有地位
- C指针原理(78)-递归(2)
- Matlab 学习 入门篇 二 数据类型
- 引用, 强弱引用, 事件机制与垃圾回收的关系及应用法则
- 挑战:截取bing正规和20进制的加法