MOOC 01-复杂度2 Maximum Subsequence Sum
Posted zjsaipplp
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MOOC 01-复杂度2 Maximum Subsequence Sum相关的知识,希望对你有一定的参考价值。
#include <stdio.h>
int main(){
int n, flag = 1, first_flag = 1, positive_flag = 0;
int sum = 0, summax = 0;
int st = 0, end = 0, st_max = 0, end_max = 0, first = 0;
scanf("%d", &n);
for(int i = 0; i < n; i++){
scanf("%d", &end);
first_flag && (first = end) && (first_flag = 0); // 短路求值
end >= 0 && (positive_flag = 1); // 短路求值
!flag || (flag = 0) || (st = end); // 短路求值
sum += end;
if (summax < sum){
summax = sum;
st_max = st;
end_max = end;
}
!(sum < 0)||!(flag = 1)||(sum = 0); // 短路求值
}
if (positive_flag)
printf("%d %d %d", summax, st_max, end_max);
else
printf("%d %d %d", summax, first, end);
return 0;
}
以上是关于MOOC 01-复杂度2 Maximum Subsequence Sum的主要内容,如果未能解决你的问题,请参考以下文章