zoukankan      html  css  js  c++  java
  • 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 sum?
    Input
    There are multiple test cases.
    First line of each case contains a single integer n.(1≤n≤105)
    Next line contains n integers A1,A2....An.(0≤Ai≤104)
    It's guaranteed that ∑n≤106.

     
    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

    思路:令Ai=f(Ai)-Ai,然后求一遍最大连续子序列和就能知道最多能增加的值。

           一开始统计所有数的和ans,再加上最多增加的值就是答案了。

     1 #pragma comment(linker, "/STACK:1024000000,1024000000")
     2 #include<iostream>
     3 #include<cstdio>
     4 #include<cstring>
     5 #include<cmath>
     6 #include<math.h>
     7 #include<algorithm>
     8 #include<queue>
     9 #include<set>
    10 #include<bitset>
    11 #include<map>
    12 #include<vector>
    13 #include<stdlib.h>
    14 #include <stack>
    15 using namespace std;
    16 #define PI acos(-1.0)
    17 #define max(a,b) (a) > (b) ? (a) : (b)
    18 #define min(a,b) (a) < (b) ? (a) : (b)
    19 #define ll long long
    20 #define eps 1e-10
    21 #define MOD 1000000007
    22 #define N 100006
    23 #define inf 1e12
    24 int n;
    25 int a[N];
    26 int A[N];
    27 int main()
    28 {
    29    while(scanf("%d",&n)==1){
    30       int ans=0;
    31       for(int i=0;i<n;i++){
    32          scanf("%d",&a[i]);
    33          ans+=a[i];
    34       }
    35       for(int i=0;i<n;i++){
    36          A[i]=(a[i]*1890+143)%10007-a[i];
    37          //printf("===%d
    ",A[i]);
    38       }
    39       int ThisSum=0,MaxSum=0;
    40       for(int i=0;i<n;i++){
    41          ThisSum+=A[i];
    42          if(ThisSum>MaxSum){
    43             MaxSum=ThisSum;
    44          }else if(ThisSum<0){
    45             ThisSum=0;
    46          }
    47       }
    48       ans+=MaxSum;
    49       printf("%d
    ",ans);
    50 
    51    }
    52     return 0;
    53 }
    View Code
  • 相关阅读:
    centos 7.0 yum 分开安装 LAMP 环境 +zabbix3.4环境
    互联网产品接入支付功能如何测试?
    python实现:将文本文件分割成多个小文本文件(php也可实现)
    『危机领导力』告诉我们如何带好团队
    Fiddler显示服务器IP的方法
    Google PageSpeed Tools 性能测试分析
    写给浮躁的测试工程师一封信
    数据库事务和锁
    测试工作中ADB命令实战
    git使用基础
  • 原文地址:https://www.cnblogs.com/UniqueColor/p/5005119.html
Copyright © 2011-2022 走看看