题目链接: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....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
 
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#define MAX 100000
#define LL long long
using namespace std;
LL fun(LL x)
{
return ((1890*x)%10007+143%10007)%10007;
}
int main()
{
int n,m,j,i,k;
int s[MAX],a[MAX],b[MAX];
while(scanf("%d",&n)!=EOF)
{
int sun=0;
for(i=1;i<=n;i++)
{
scanf("%d",&s[i]);
a[i]=fun(s[i]);//储存 f(x);
b[i]=a[i]-s[i];//储存f(x)和x的差值
sun+=s[i];
}
int sum=0;
int Max=0;
for(i=1;i<=n;i++)//最大子段和代码
{
if(sum<=0)
sum=b[i];
else
sum+=b[i];
Max=max(Max,sum);//求出最大子段
}
printf("%d\n",sun+Max);
}
return 0;
}

  

hdu 5586 Sum【dp最大子段和】的更多相关文章

  1. hdu 5586 Sum 最大子段和

    Sum Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5586 Desc ...

  2. hdu 5586 Sum 基础dp

    Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Desc ...

  3. hdu 5586 Sum(dp+技巧)

    Problem Description There )mod10007.After that,the sum of n numbers should be as much as possible.Wh ...

  4. POJ2479 Maximum sum[DP|最大子段和]

    Maximum sum Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 39599   Accepted: 12370 Des ...

  5. hdu 5586 sum

    Problem Description There is a number sequence A1,A2....An,you can select a interval [l,r] or not,al ...

  6. HDU - 5586 Sum(区间增量最大)

    题意:将数组A的部分区间值按照函数f(Ai)=(1890*Ai+143)mod10007修改值,区间长度可以为0,问该操作后数组A的最大值. 分析:先求出每个元素的增量,进而求出增量和.通过b[r]- ...

  7. HDOJ(HDU).1003 Max Sum (DP)

    HDOJ(HDU).1003 Max Sum (DP) 点我挑战题目 算法学习-–动态规划初探 题意分析 给出一段数字序列,求出最大连续子段和.典型的动态规划问题. 用数组a表示存储的数字序列,sum ...

  8. HDU 2836 (离散化DP+区间优化)

    Reference:http://www.cnblogs.com/wuyiqi/archive/2012/03/28/2420916.html 题目链接: http://acm.hdu.edu.cn/ ...

  9. hdu 3507 斜率dp

    不好理解,先多做几个再看 此题是很基础的斜率DP的入门题. 题意很清楚,就是输出序列a[n],每连续输出的费用是连续输出的数字和的平方加上常数M 让我们求这个费用的最小值. 设dp[i]表示输出前i个 ...

随机推荐

  1. android 多个listView的向下滚动设置 listView动态设置高度代码

    墨迹天气图: 这里都是用的android里面的shape实现的,实现起来比较简单,只是在滚动的时候有点小麻烦... 当我们多个ListView超出了它的父控件LinearLayout的时候,它们每个L ...

  2. C语言itoa()函数和atoi()函数详解(整数转字符)

    http://c.biancheng.net/cpp/html/792.html C语言提供了几个标准库函数,可以将任意类型(整型.长整型.浮点型等)的数字转换为字符串. 以下是用itoa()函数将整 ...

  3. mybatis知识点

    1.Mybatis比IBatis比较大的几个改进是什么 a.有接口绑定,包括注解绑定sql和xml绑定Sql , b.动态sql由原来的节点配置变成OGNL表达式, c. 在一对一,一对多的时候引进了 ...

  4. javascript高级程序设计读书笔记

    第2章  在html中使用javascript 一般都会把js引用文件放在</body>前面,而不是放在<head>里, 目的是最后读取js文件以提高网页载入速度. 引用js文 ...

  5. Oracle 列顺序测试

    列顺序测试 大家在做表设计的时候通常对表中列的排列顺序没有过多注意,但是其实越常用的列,它的位置越靠前,则查询速度越快. 因为每个block里面存储了row directory (每行数据在块中的位移 ...

  6. poj 1442 Black Box(堆 优先队列)

    题目:http://poj.org/problem?id=1442 题意:n,m,分别是a数组,u数组的个数,u[i]w为几,就加到a几,然后输出第i 小的 刚开始用了一个小顶堆,超时,后来看了看别人 ...

  7. JAVA高级特性 - 注解

    注解是插入到代码中用于某种工具处理的标签.这些标签可以在源码层次上进行操作,或者可以处理编译器将其纳入到注解类文件中. 注解不会改变对程序的编译方式.Java编译器会对包含注解和不包含注解的代码生成相 ...

  8. SPOJ-OPTM Optimal Marks ★★(按位建图 && 最小割)

    [题意]给出一个无向图,每个点有一个标号mark[i],不同点可能有相同的标号.对于一条边(u, v),它的权值定义为mark[u] xor mark[v].现在一些点的标号已定,请决定剩下点的标号, ...

  9. OK335xS davinci mdio driver hacking

    /******************************************************************************* * OK335xS davinci m ...

  10. file的getPath getAbsolutePath和getCanonicalPath的区别

    转自:http://www.blogjava.net/dreamstone/archive/2007/08/08/134968.html file的这几个取得path的方法各有不同,下边说说详细的区别 ...