PAT - 测试 01-复杂度2 Maximum Subsequence Sum (25分)
1, N2N_2N2, ..., NKN_KNK }. A continuous subsequence is defined to be { NiN_iNi, Ni+1N_{i+1}Ni+1, ..., NjN_jNj } where 1≤i≤j≤K1 \le i \le j \le K1≤i≤j≤K. The Maximum Subsequence is the continuous subsequence which has the largest sum of its elements. For example, given sequence { -2, 11, -4, 13, -5, -2 }, its maximum subsequence is { 11, -4, 13 } with the largest sum being 20.
Now you are supposed to find the largest sum, together with the first and the last numbers of the maximum subsequence.
Input Specification:
Each input file contains one test case. Each case occupies two lines. The first line contains a positive integer KKK (≤10000\le 10000≤10000). The second line contains KKK numbers, separated by a space.
Output Specification:
For each test case, output in one line the largest sum, together with the first and the last numbers of the maximum subsequence. The numbers must be separated by one space, but there must be no extra space at the end of a line. In case that the maximum subsequence is not unique, output the one with the smallest indices iii and jjj (as shown by the sample case). If all the KKK numbers are negative, then its maximum sum is defined to be 0, and you are supposed to output the first and the last numbers of the whole sequence.
Sample Input:
10
-10 1 2 3 4 -5 -23 3 7 -21
Sample Output:
),第二行输入KKK个数,以空格为分割。输出:对于每一个测试的情况下,在一个行中的最大总和的输出,与第一和最大序列的最后数字。数字必须用一个空格分开,但最后一个数后没有空格。在该最大序列不是唯一的情况下,输出一个具有最小索引的数。如果输入的所有的数都是负数,则它的最大总和被定义为0,你应该输出的第一和整个序列的最后一个数。============================第一次code:
#include <stdio.h> #include <stdlib.h> void MaxSubseSum(int n); int main(void) { int n; scanf("%d",&n); MaxSubseSum(n); ; } void MaxSubseSum(int n) { ,MaxSum=,start=,end=,start1=,flag=; int a[n]; ;i<n;i++) { scanf("%d",&a[i]); } ;i<n;i++) { ThisSum += a[i]; ) flag = ; if(ThisSum > MaxSum) { start = start1; MaxSum = ThisSum; end = i; } ) { ThisSum = ; start1=i+; } } ) { ) { printf(],a[n-]); } else { printf("0 0 0"); } } else { printf("%d %d %d",MaxSum,a[start],a[end]); } }
PAT - 测试 01-复杂度2 Maximum Subsequence Sum (25分)的更多相关文章
- 中国大学MOOC-陈越、何钦铭-数据结构-2015秋 01-复杂度2 Maximum Subsequence Sum (25分)
01-复杂度2 Maximum Subsequence Sum (25分) Given a sequence of K integers { N1,N2, ..., NK }. ...
- PTA 01-复杂度2 Maximum Subsequence Sum (25分)
题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/663 5-1 Maximum Subsequence Sum (25分) Given ...
- 01-复杂度2 Maximum Subsequence Sum (25 分)
Given a sequence of K integers { N1, N2, ..., NK }. A continuous subsequence is defined to ...
- 1007 Maximum Subsequence Sum (25分) 求最大连续区间和
1007 Maximum Subsequence Sum (25分) Given a sequence of K integers { N1, N2, ..., NK }. A ...
- 1007 Maximum Subsequence Sum (25 分)
1007 Maximum Subsequence Sum (25 分) Given a sequence of K integers { N1, N2, ..., NK }. A ...
- 数据结构练习 01-复杂度2. Maximum Subsequence Sum (25)
Given a sequence of K integers { N1, N2, ..., NK }. A continuous subsequence is defined to be { Ni, ...
- 01-复杂度2. Maximum Subsequence Sum (25)
Given a sequence of K integers { N1, N2, ..., NK }. A continuous subsequence is defined to be { Ni, ...
- PAT Advanced 1007 Maximum Subsequence Sum (25 分)
Given a sequence of K integers { N1, N2, ..., NK }. A continuous subsequence is defined to ...
- PAT 1007 Maximum Subsequence Sum (25分)
题目 Given a sequence of K integers { N1 , N2 , ..., NK }. A continuous subsequence is define ...
随机推荐
- ABBYY FineReader 12对系统有哪些要求
ABBYY FineReader是市场领先的ocr文字识别软件,可快速方便地将扫描的文档.PDF文档和图像文件(包括数码照片)转化为可编辑.可搜索的格式.每个软件都有其安装运行的系统要求,ABBYY ...
- 简述Session
Session的原理 1.session技术的概述 * session是服务器端技术 * 服务器在运行时可以为每一个用户的浏览器创建一个其独享的session对象 * 由于session为用户浏览器独 ...
- fedora wine qq
http://blog.lilydjwg.me/2015/10/26/run-tencent-qq-lite-with-wine.186640.html
- linux shell:nginx日志切割脚本
需求原因:nginx不具备日志切割功能,日志量较大,方便分析. 实现目的:完成nginx日志切割,并根据时间命名 简要命令: mv /usr/local/tengine/logs/access.l ...
- spring mvc 参数
Struts(表示层)+Spring(业务层)+Hibernate(持久层) Struts: Struts是一个表示层框架,主要作用是界面展示,接收请求,分发请求. 在MVC框架中,Struts属于V ...
- WPF ListBox
记录一些ListBox的用法 设置ListBox选中项的背景颜色 如何为标准的ListBox添加ItemClick事件 连续选择同一项时SelectionChanged 事件不响应的问题 1.设置Li ...
- python---difflib
文件内容差异对比 difflib为python的标准库模块,无需安装.作用时对比文本之间的差异.并且支持输出可读性比较强的HTML文档,与LInux下的diff 命令相似.在版本控制方面非常有用. # ...
- mysql5.5字符集设置的一点变化(对于中文乱码问题,需要设置mysql字符集)
工作中因为字符集问题没少头疼,还犯过一次错误,还好拯救及时,没有发生重大事故,唉,弄清楚点还是非常有必要的: 例如我的工作环境为CTR+redhat5+mysql5.5 在导入sql语句的时候必须要注 ...
- OAF_开发系列10_实现OAF动态LOV设定
20150712 Created By BaoXinjian
- contains 方法
不管在c#中还是java中,很多类型都有contains方法.它的原理是什么? 看一个java的例子 http://blog.csdn.net/fwwdn/article/details/674684 ...