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≤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

BestCoder Round #64 (div.2)

题目链接:点击传送

思路:基础dp;

   dp[i][0]表示dp前边没有改成f的总和

   dp[i][1]表示可以继续改成f的总和;

   dp[i][2]表示不可以继续改成f的总和;

dp[i][0]=dp[i-1][0]+a[i];
dp[i][1]=max(dp[i-1][1]+b[i],dp[i-1][0]+b[i]);
dp[i][2]=max(dp[i-1][2]+a[i],dp[i-1][1]+a[i]);

   b=f(a);

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
#define bug(x)  cout<<"bug"<<x<<endl;
const int N=1e5+30010,M=1e6+10,inf=2147483647;
const ll INF=1e18+10,mod=2147493647;
ll a[N],b[N],dp[N][4];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]),b[i]=(1890*a[i]+143)%10007;
        dp[0][0]=dp[0][1]=dp[0][2]=0;
        for(int i=1;i<=n;i++)
        {
            dp[i][0]=dp[i-1][0]+a[i];
            dp[i][1]=max(dp[i-1][1]+b[i],dp[i-1][0]+b[i]);
            dp[i][2]=max(dp[i-1][2]+a[i],dp[i-1][1]+a[i]);
        }
        printf("%lld\n",max(dp[n][2],max(dp[n][0],dp[n][1])));
    }
    return 0;
}
时间: 2024-08-24 16:39:01

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+技巧)

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

Monkey and Banana HDU - 1069 (基础dp)

Monkey and Banana A group of researchers are designing an experiment to test the IQ of a monkey. They will hang a banana at the roof of a building, and at the mean time, provide the monkey with some blocks. If the monkey is clever enough, it shall be

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 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 142742    Accepted Submission(s): 33225 Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max s

HDU 1422 重温世界杯 基础DP 好题

重温世界杯 Problem Description 世界杯结束了,意大利人连本带利的收回了法国人6年前欠他们的债,捧起了大力神杯,成就了4星意大利.世界杯虽然结束了,但是这界世界杯给我们还是留下许多值得回忆的东西.比如我们听到了黄名嘴的3分钟激情解说,我们懂得了原来可以向同一个人出示3张黄牌,我们还看到了齐达内的头不仅能顶球还能顶人…………介于有这么多的精彩,xhd决定重温德国世界杯,当然只是去各个承办世界杯比赛的城市走走看看.但是这需要一大比钱,幸运的是xhd对世界杯的热爱之情打动了德国世界杯