- 浏览: 36626 次
- 性别:
- 来自: 杭州
最新评论
求最大连续子串和
Sample Input:
10 -10 1 2 3 4 -5 -23 3 7 -21Sample Output:
10 1 4
#include <iostream> #include <vector> #include <string> using namespace std; void MaSubSum(const vector<int>& a) { int first = 0; int last = 0; long maxSum = a[0]; for (int i = 0; i < a.size(); i++) { long thisSum = 0; for (int j = i; j < a.size(); j++) { thisSum += a[j]; if (thisSum > maxSum) { first = i; last = j; maxSum = thisSum; } } } if (maxSum < 0) { cout<<"0"<<" "<<a[0]<<" "<<a[a.size() - 1]; } else { cout<<maxSum<<" "<<a[first]<<" "<<a[last]; } return; } int main() { int K; cin>>K; vector<int> V; while(K--) { int i; cin>>i; V.push_back(i); } MaSubSum(V); return 0; }
发表评论
-
PAT1013 Battle Over Cities
2012-11-29 23:59 773Sample Input 3 2 3 1 2 1 3 ... -
PAT1003 Emergency
2012-11-29 23:46 661Sample Input 5 6 0 2 1 2 1 ... -
PAT1041 Be Unique
2012-11-23 23:43 759找出只出现过一次的数,用各种排序必然超时,需要用数组做hash ... -
PAT1042 Shuffling Machine
2012-11-23 23:42 733扑克洗牌 #include < ... -
PAT1040 Longest Symmetric String
2012-11-23 23:41 957求最长回文子串 #include < ... -
PAT1036 Boys vs Girls
2012-11-23 23:41 715Sample Input 1: 3 Joe M Mat ... -
PAT1035 Password
2012-11-23 23:40 616Sample Input 1: 3 Team0000 ... -
PAT1031 Hello World for U
2012-11-22 23:54 653Sample Input: helloworld! S ... -
PAT1029 Median
2012-11-22 23:54 651用标准库的排序全部超时,需要自己实现,另外还不能用cin co ... -
PAT1028 List Sorting
2012-11-22 23:53 807用vector最后一个用例超时了。。。 Sample ... -
PAT1027 Colors in Mars
2012-11-22 23:52 622Sample Input 15 43 71 Samp ... -
PAT1025 PAT Ranking
2012-11-22 23:51 771Sample Input: 2 5 123456789 ... -
PAT1023 Have Fun with Numbers
2012-11-21 23:55 685大数的相加 比较两个字符串中字符完全相同 Sa ... -
PAT1020 Tree Traversals
2012-11-21 23:54 652已知中序遍历 后序遍历,求层次遍历 Sample In ... -
PAT1019 General Palindromic Number
2012-11-21 23:53 537十进制转任意进制,并比较是否是回文数 Sample I ... -
PAT1037 Magic Coupon
2012-11-21 15:46 662Sample Input: 4 1 2 4 -1 ... -
PAT1038 Recover the Smallest Number
2012-11-20 23:52 1668由一道面试题改的 把数组排成最小的数 不同之处是这 ... -
PAT1024 Palindromic Number
2012-11-20 23:51 647Sample Input 1: 67 3 Sampl ... -
PAT1015 Reversible Primes
2012-11-19 23:51 771十进制转任意进制 假设十进制数为number,转 ... -
PAT1012 The Best Rank
2012-11-19 23:50 926四门功课,输出排名最高的是哪个 Sample Inpu ...
相关推荐
Finding Maximum Contiguous Subsequence Sum using divide-and-conquer approach
前言k-Maximum Subsequence Sum - 模型结合这个模型的性质,我们可以发现我们每次要么选择一个与已有区间完全不相交的区间,要么从已有区间中
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 ...
最大子序列和算法的运行时间 衡量执行时间
动态规划 poj Common Subsequence c++ cpp文件
LCS Longest (maximum) common subsequence
最大子序列和该算法采用向量(数组)并找到它的最大子序列和: node max-subsequence-sum.js [2,-4,6,8,-10,100,-6,5]
Longest Ordered Subsequence,算法分析与设计,C语言程序
北大POJ2533-Longest Ordered Subsequence【O(nlogn)】
Extracting Article Text from the Web with Maximum Subsequence Segmentation 论文 MMS算法。
活动选择(Activity Selection) 备选列表排列(Alternative List Arrange) Davis–Putnam–Logemann–Loveland算法 Dijkstra银行家算法(Dijkstra ...最大子序列(Maximum Subsequence) 嵌套括号(Nested Brackets
Pku acm 第2533题 Longest Ordered Subsequence 代码,有详细的注释,动态规划
Pku acm 第1458题 Common Subsequence 代码,有详细的注释,动态规划
北大POJ2533-Longest Ordered Subsequence 解题报告+AC代码
Estimating the Longest Increasing Subsequence in Nearly Optimal Time_在近似最优时间内估计最长增长子序列.pdf
北大POJ2533-Longest Ordered Subsequence【O(n^2)】
Windowed subsequence matching over deterministic strings has been studied in previous work in the contexts of knowledge discovery, data mining, and molecular biology. However, we observe that in these...
Common Subsequence 动态规划 java(csdn)————程序
Binary Tree Maximum Path Sum Populating Next Right Pointers in Each Node Sum Root to Leaf Numbers LCA of Binary Tree 线段树 Range Sum Query - Mutable 排序 插入排序 Insertion Sort List 归并排序 Merge ...