• HDU 5586 (dp 思想)


    Sum

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 507    Accepted Submission(s): 284
    Problem Description
    There is a number sequence A1,A2....An

    ,
    A1,A2....An

    ,
    A1,A2....An

    ,
    A1,A2....An

    ,
    A1,A2....An

    ,
    A1,A2....An

    ,
    A1,A2....An
    ,you can select a interval [l,r] or not,all the numbers Ai(lir)
    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 sum?
     
    Input
    There are multiple test cases. First line of each case contains a single integer n.(1n105)
    Next line contains n integers A1,A2....An
    .(0Ai104)
    It's guaranteed that n106
    .
     
    Output
    For each test case,output the answer in a line.
     
    Sample Input
    2
    10000 9999
    5
    1 9999 1 9999 1
     
    Sample Output
    19999 22033
     
    Source
     
    传送门 http://acm.hdu.edu.cn/showproblem.php?pid=5586
    类似杭电1003
    题意  一串序列 可以只能更改一个区间 或不更改f(x)=(1890x+143)mod10007    更改操作为f(x)=(1890x+143)mod10007
    询问 这串序列的和的最大值
    做一个变形 每个值变为 f(x)-x 然后按照1003的方法 求最大连续区间的和 
    dp[i]=max(dp[i],dp[i-1]+dp[i]);
     
    f(x)=(1890x+143)mod10007
     
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    int n;
    int bac(int s)
    {
        return (1890*s+143)%10007;
    }
    int b[100005],a[100005];
    int main()
    {
        while(scanf("%d",&n)!=EOF)
        {
            memset(b,0,sizeof(b));
            memset(a,0,sizeof(a));
            int re=0;
            for(int i=0;i<n;i++)
                {
                    scanf("%d",&a[i]);
                    re=re+a[i];
                    b[i]=bac(a[i])-a[i];
                }
              //  int exm=0;
                int maxn=0;
              for(int i=1;i<n;i++)
              {
                  if(b[i]+b[i-1]>b[i])
                    b[i]=b[i]+b[i-1];
           if(b[i]>maxn)
                         maxn=b[i];
    
              }
            printf("%d
    ",re+maxn);
        }
        return 0;
    }
    
  • 相关阅读:
    yarn 0.9.0 build spark
    redhat6.4上build storm 0.9.0.1
    redhat6.4安装storm集群-4节点
    Hadoop 2.2.0 4结点集群安装 非HA
    redhat6.4上安装mysql
    redhat6.4上用apache建立os repos
    Hive Over HBase
    Hadoop 2.2.0学习笔记20131210
    Hadoop 2.2.0学习笔记20131209
    IDH2.5.1. Pain Points
  • 原文地址:https://www.cnblogs.com/hsd-/p/5008883.html
Copyright © 2020-2023  润新知