HDU 5586 Sum

最大子串和

#include<cstdio>
#include<cstring>

const int maxn=100000+10;
int n;
int x[maxn];
int fx[maxn];
int a[maxn];
int sum[maxn];
int L[maxn],R[maxn];

const int INF=0x7FFFFFFF;

int max(int a,int b)
{
    if(a>b) return a;
    return b;
}
int main()
{
    int N;
    while(~scanf("%d",&N)){
    int SS=0;
    for(int i=1;i<=N;i++)
    {
        scanf("%d",&x[i]);
        SS=SS+x[i];
    }
    for(int i=1;i<=N;i++)
        fx[i]=(1890*x[i]+143)%10007;

    for(int i=1;i<=N;i++) a[i]=fx[i]-x[i];

    sum[1]=a[1]; L[1]=1;R[1]=1;
    for(int i=2;i<=N;i++)
    {
        if(sum[i-1]+a[i]>=a[i])
        {
               sum[i]=sum[i-1]+a[i];
               L[i]=L[i-1];
                R[i]=i;
         }
         else
         {
             sum[i]=a[i];
             L[i]=i;
             R[i]=i;
          }
     }
    int Max=-INF;
    for(int i=1;i<=N;i++)
       if(sum[i]>Max) Max=sum[i];

    int ans=max(SS,SS+Max);
    printf("%d\n",ans);
    }
    return 0;
}
时间: 2024-08-04 03:49:47

HDU 5586 Sum的相关文章

hdu 5586 Sum【dp最大子段和】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5586 Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 677    Accepted Submission(s): 358 Problem Description There is a number sequence A1,A2...

hdu 5586 Sum 最大子段和

Sum Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5586 Description There is a number sequence A1,A2....An,you can select a interval [l,r] or not,all the numbers Ai(l≤i≤r) will become f(Ai).f(x)=(1890x+143)mod1

hdu 5586 Sum(dp+技巧)

Problem Description There is a number sequence A1,A2....An,you can select a interval [l,r] or not,all the numbers Ai(l≤i≤r) will become f(Ai).f(x)=(1890x+143)mod10007.After that,the sum of n numbers should be as much as possible.What is the maximum s

hdu 5586 Sum 基础dp

Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description There is a number sequence A1,A2....An,you can select a interval [l,r] or not,all the numbers Ai(l≤i≤r) will become f(Ai).f(x)=(1890x+143)mod1

Hdu 5586 sum【最大连续子序列和】

SUM Description There is a number sequence ,you can select a interval [l,r] or not,all the numbers  will become ..After that,the sum of n numbers should be as much as possible.What is the maximum sum? Input There are multiple test cases. First line o

HDU - 5586 Sum(区间增量最大)

题意:将数组A的部分区间值按照函数f(Ai)=(1890*Ai+143)mod10007修改值,区间长度可以为0,问该操作后数组A的最大值. 分析:先求出每个元素的增量,进而求出增量和.通过b[r]-b[l-1]求区间增量和,枚举r,而b[l-1]则是b[r]前所有元素的最小值,注意mi初始化为0,因为当前有可能的最优值为区间0~r. #pragma comment(linker, "/STACK:102400000, 102400000") #include<cstdio>

hdu 1258 Sum It Up (dfs+路径记录)

Sum It Up Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3953    Accepted Submission(s): 2032 Problem Description Given a specified total t and a list of n integers, find all distinct sums usi

HDU 4704 Sum( 费马小定理 )

HDU 4704 Sum( 费马小定理 ) 理解能力果然拙计,,题目看半天没懂什么意思. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long LL; #define MOD 1000000007 char str[100010]; LL fast_mod( LL a, int b) { LL res = 1; while( b )

hdu 4704 Sum (费马小定理+快速幂)

//(2^n-1)%mod //费马小定理:a^n ≡ a^(n%(m-1)) * a^(m-1)≡ a^(n%(m-1)) (mod m) # include <stdio.h> # include <algorithm> # include <string.h> # define mod 1000000007 using namespace std; __int64 pow(__int64 n) { __int64 p=1,q=2; while(n) { if(n%