HDU 5586 Sum

来源:互联网 发布:淘宝卖家体检中心在哪 编辑:程序博客网 时间:2024/05/01 21:11


题意:给一个序列,现在选择或不选择一个连续的区间,把区间里面的每一个数x转化成f(x)=(1890x+143)mod10007f(x)=(1890*a[i]+143)%10007问你最后这个区间的最大和是多少?


想法:有两种可能,一种是不需要选择任何一个区间,因为原区间和就是最大的,还有一种就是需要选择一个区间,那么增加的就是这个区间增加的数,所以题目转化为求一个区间使得区间里的数的和变化前后差值为正且最大。

<strong><span style="font-family:Comic Sans MS;font-size:24px;"></span></strong><pre class="cpp" name="code">#include<stdio.h>#include<string.h>int a[100000+5];int main(){int n;while(~scanf("%d",&n)){__int64 sum=0;for(int i=1;i<=n;i++){scanf("%d",&a[i]);sum+=a[i];}int st,ed,s,t;__int64 maxcha,cha;s=1;maxcha=0,cha=0;for(int i=1;i<=n;i++){int fx=(1890*a[i]+143)%10007;int k=fx-a[i];cha+=k;if(cha<0){s=i+1;cha=0;}else {t=i;}if(cha>maxcha){maxcha=cha;st=s;ed=t;}}printf("%I64d\n",sum+maxcha);}return 0;} 

0 0