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)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≤10^5)
Next line contains n integers A1,A2....An.(0≤Ai≤10^4)
It‘s guaranteed that ∑n≤10^6.

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

题意:

给一个数组,选一个区间[l,r]把a[i]变成f(a[i]),也可以不选,问最后得到的这个数组的和最大是多少;

思路:

p[i]=(1890*a[i]+143)%10007;

然后就是在p[i]中找一个连续喝最大的字串,然后就好了;水题;

AC代码:

//#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <cstring>
#include <algorithm>
#include <cstdio>

using namespace std;
#define Riep(n) for(int i=1;i<=n;i++)
#define Riop(n) for(int i=0;i<n;i++)
#define Rjep(n) for(int j=1;j<=n;j++)
#define Rjop(n) for(int j=0;j<n;j++)
#define mst(ss,b) memset(ss,b,sizeof(ss));
typedef long long LL;
template<class T> void read(T&num) {
    char CH; bool F=false;
    for(CH=getchar();CH<‘0‘||CH>‘9‘;F= CH==‘-‘,CH=getchar());
    for(num=0;CH>=‘0‘&&CH<=‘9‘;num=num*10+CH-‘0‘,CH=getchar());
    F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
    if(!p) { puts("0"); return; }
    while(p) stk[++ tp] = p%10, p/=10;
    while(tp) putchar(stk[tp--] + ‘0‘);
    putchar(‘\n‘);
}

const LL mod=1e9+7;
const double PI=acos(-1.0);
const LL inf=1e14;
const int N=1e4+15;
const int maxn=18;

int p[10*N],a[10*N];
LL dp[10*N];
int main()
{
    int n;
    while(cin>>n)
    {
        LL sum=0,ans=0;
        Riep(n)read(a[i]),p[i]=(1890*a[i]+143)%10007-a[i],sum=sum+a[i];
        dp[0]=0;
        for(int i=1;i<=n;i++)
        {
            if(dp[i-1]+p[i]<0)dp[i]=0;
            else dp[i]=dp[i-1]+p[i];
            ans=max(ans,dp[i]);
        }
        cout<<sum+ans<<"\n";
    }

        return 0;
}
时间: 2024-11-12 09:58:36

hdu-5586 Sum(dp)的相关文章

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 基础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(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 最大子段和

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

最大子串和 #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()

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 1003 Max Sum(dp,最大连续子序列和)

Max Sum Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 = 14. Input The first line of the input

hdu 4734 数位dp

http://acm.hdu.edu.cn/showproblem.php?pid=4734 Problem Description For a decimal number x with n digits (AnAn-1An-2 ... A2A1), we define its weight as F(x) = An * 2n-1 + An-1 * 2n-2 + ... + A2 * 2 + A1 * 1. Now you are given two numbers A and B, plea

HDU 3853 概率dp

LOOPS Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others) Total Submission(s): 2337    Accepted Submission(s): 951 Problem Description Akemi Homura is a Mahou Shoujo (Puella Magi/Magical Girl).Homura wants to help he