UVa 507 - Jill Rides Again
题目大意:最大和子序列问题。由于具有最大和的子序列具有一下性质:第一项不为负数,并且从第一项开始累加,中间不会有和出现负数,因为一旦有负数我们可以抛弃前边的部分以得到更大的子序列和,这将会产生矛盾。
#include <cstdio> int main()
{
#ifdef LOCAL
freopen("in", "r", stdin);
#endif
int T;
scanf("%d", &T);
for (int kase = ; kase <= T; kase++)
{
int n;
scanf("%d", &n);
int x, sum = , nicest = , len = ;
int p = , s, e;
for (int i = ; i < n-; i++)
{
scanf("%d", &x);
sum += x;
if (sum < )
{
sum = ;
p = i + ;
}
else if (sum > nicest || (sum == nicest && i-p+ > len))
{
s = p;
e = i;
len = i - p + ;
nicest = sum;
}
}
if (nicest > ) printf("The nicest part of route %d is between stops %d and %d\n", kase, s+, e+);
else printf("Route %d has no nice parts\n", kase);
}
return ;
}
UVa 507 - Jill Rides Again的更多相关文章
- UVA 507 - Jill Rides Again 动态规划
Jill Rides Again Jill likes to ride her bicycle, but since the pretty city of Greenhills where sh ...
- uva507 - Jill Rides Again(最长连续和)
option=com_onlinejudge&Itemid=8&page=show_problem&problem=448">题目:uva507 - Jill ...
- <算法竞赛入门经典> 第8章 贪心+递归+分治总结
虽然都是算法基础,不过做了之后还是感觉有长进的,前期基础不打好后面学得很艰难的,现在才慢慢明白这个道理. 闲话少说,上VOJ上的专题训练吧:http://acm.hust.edu.cn/vjudge/ ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- POJ 3342 Party at Hali-Bula / HDU 2412 Party at Hali-Bula / UVAlive 3794 Party at Hali-Bula / UVA 1220 Party at Hali-Bula(树型动态规划)
POJ 3342 Party at Hali-Bula / HDU 2412 Party at Hali-Bula / UVAlive 3794 Party at Hali-Bula / UVA 12 ...
- uva 156 - Ananagrams (反片语)
csdn:https://blog.csdn.net/su_cicada/article/details/86710107 例题5-4 反片语(Ananagrams,Uva 156) 输入一些单词,找 ...
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
随机推荐
- java+tomcat+Eclipse+mysql配置
Java下载及配置: 1. 下载:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html ...
- Ubuntu系统搭建PPTP,VPN
1.先安装pptp apt-get install pptpd 2.打开pptp的DNS vim /etc/ppp/option.pptpd 去掉下面两行内容前的# ms-dns 8.8.8.8 ms ...
- Bcdedit命令使用详解使用方法
XP,WIN2003,VISTA,万indows,WIN2008多盘多系统多引导bcdedit的使用windows出了新系统vista,2008想赏赏鲜学习学习~~但又习惯于用旧的XP,2003,然而 ...
- FragmentActivity
子fragment 调用 FragmentActivity ((FragmentActivity) getActivity()).updateUnreadLabel(); FragmentActivi ...
- javascript 中 apply(或call)方法的用途----对象的继承
一直以来,我的理解就是 js中的Function.apply(或者是Function.call)方法是来改变Function 这个函数的执行上下文(excute Context),说白了,就是改变执 ...
- 转:总结Selenium WebDriver中一些鼠标和键盘事件的使用
在使用 Selenium WebDriver 做自动化测试的时候,会经常模拟鼠标和键盘的一些行为.比如使用鼠标单击.双击.右击.拖拽等动作:或者键盘输入.快捷键使用.组合键使用等模拟键盘的操作.在 W ...
- 解决Ubuntu系统中文乱码显示问题,终端打开文件及查看目录
解决Ubuntu系统中文乱码显示问题 [日期:2014-02-20] 来源:Linux社区 作者:njchenyi [字体:大 中 小] 我是先安装了Ubuntu 12.04 Server,然后 ...
- H2Database高级特性
http://wenku.baidu.com/link?url=mcSOmh5PRsKGO1kXzXqzZVjVPYR5sOWK_KIjw8qdpGHAkZsbWiK71lE9ToYwxLvJwL7b ...
- python之路: 线程、进程和协程
进程和线程 既然看到这一章,那么你肯定知道现在的系统都是支持“多任务”的操作,比如: Mac OS X,UNIX,Linux,Windows等. 多任务:简单地说就是同时运行多个任务.譬如:你可以一边 ...
- Vasiliy's Multiset
Vasiliy's Multiset time limit per test 4 seconds memory limit per test 256 megabytes input standard ...