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
  • 相关阅读:
    根据navigator.userAgent返回值识别 浏览器
    HTML兼容问题及解决办法
    css 浏览兼容问题及解决办法 (2)
    css 浏览兼容问题及解决办法 (1)
    js 浏览器兼容问题及解决办法
    cookie 笔记
    HTML5基础2
    HTML5基础1
    摩天轮
    造个惊喜盒( ๑ŏ ﹏ ŏ๑ )
  • 原文地址:https://www.cnblogs.com/UniqueColor/p/5005119.html
Copyright © 2011-2022 走看看