HDU1003+最大连续子序列和+起始终止位置
2013-03-23 13:08
281 查看
View Code
/* 最大连续上升子序列和 */ #include<stdio.h> #include<string.h> #include<stdlib.h> #include<algorithm> #include<iostream> #include<queue> //#include<map> #include<math.h> using namespace std; typedef long long ll; //typedef __int64 int64; const int maxn = 100005; const int inf = 0x7fffffff; const double pi=acos(-1.0); const double eps = 1e-8; int a[ maxn ]; int pos_s,pos_t,max_sum; void LIS( int a[],int n ){ int tmp_pos,tmp_sum ; pos_s = pos_t = tmp_pos = 1; max_sum = tmp_sum = a[ 1 ]; for( int i=2;i<=n;i++ ){ if( tmp_sum+a[ i ]<a[ i ] ){ tmp_sum = a[ i ]; tmp_pos = i; } else{ tmp_sum += a[ i ]; }//当前 tmp_sum 的值就表示前面所有的最大的值的那个,且一定包含a[i-1] if( tmp_sum>max_sum ){ max_sum = tmp_sum; pos_s = tmp_pos; pos_t = i; }//从1到n扫描 暗示 着 pos_s最小,如果存在多个ans的话 } } int main(){ int ca; scanf("%d",&ca); for( int t=1;t<=ca;t++ ){ if( t!=1 ) printf("\n"); int n; scanf("%d",&n); for( int i=1;i<=n;i++ ) scanf("%d",&a[ i ]); LIS( a,n ); printf("Case %d:\n%d %d %d\n",t,max_sum,pos_s,pos_t); } return 0; }
相关文章推荐
- 最大连续子序列和及其起始位置(未测试)
- HDU 1231 最大连续子序列——最大连续和+输出其起始点
- 题目1011:最大连续子序列(需要标记边界位置)
- hdu 1231_最大字段及其起始、终止位置
- (java)整数数组中求最大连续子序列之和,并且记录开始和结束位置
- 最大子序列和问题及其起始位置
- 编程之美2.14扩展问题2 求数组的子数组之和的最大值并给出子数组的起始终止位置
- poj1231最大连续子序列和并输出子列的位置
- (java)整数数组中求最大连续子序列之和,并且记录开始和结束位置
- poj1231最大连续子序列和并输出子列的位置
- 编程之美2.14扩展问题2 求数组的子数组之和的最大值并给出子数组的起始终止位置
- 【PAT】1007 Maximum Subsequence Sum (25) 最大连续子序列和 +记录位置
- HDU - 1003 Max Sum(连续子序列最大和)
- hdu1231 最大连续子序列
- hdu 1231 最大连续子序列和
- 最大连续子序列乘积
- 最大连续子序列
- 最大连续子序列和,最大上升子序列和,最长上升子序列,最长公共子串,最长公共子序列,最长上升公共子序列
- 最大连续子序列-最基础的DP
- HDU 1231:最大连续子序列(DP)