题目链接: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. Amzon MWS API开发之订单接口

    Amazon订单接口是Amazon MWS 开发接口中的一大块,我们可以通过接口调用来获得订单数据. 在调用接口之前,首先我们要获得相关店铺商家的店铺密钥等信息.如下: 在此我将所有信息定义在一个类中 ...

  2. CKEditor在线编辑器增加一个自定义插件

    CKEditor是一个非常优秀的在线编辑器,它的前身就是FCKEditor,CKEditor据官方说是重写了内核的,但功能和性能比FCKEditor更为强大和优越.记得07年的时候第一次接触FCKEd ...

  3. js jquery学习

    1.js api   http://api.vfreesoft.com/ 2.26个jquery小技巧  http://www.cnblogs.com/shouce/p/5084565.html 3. ...

  4. 【零基础学习iOS开发】【02-C语言】11-函数的声明和定义

    在上一讲中,简单介绍了函数的定义和使用,只要你想完成一个新功能,首先想到的应该是定义一个新的函数来完成这个功能.这讲继续介绍函数的其他用法和注意事项. 一.函数的声明 1.在C语言中,函数的定义顺序是 ...

  5. ios开发--网页中调用JS与JS注入

    先将网页弄到iOS项目中: 网页内容如下, 仅供测试: <html> <head> <meta xmlns="http://www.w3.org/1999/xh ...

  6. 【HDOJ】4358 Boring counting

    基本思路是将树形结构转线性结构,因为查询的是从任意结点到叶子结点的路径.从而将每个查询转换成区间,表示从该结点到叶子结点的路径.离线做,按照右边界升序排序.利用树状数组区间修改.树状数组表示有K个数据 ...

  7. 1628. White Streaks(STL)

    1628 题意不太好理解 求横黑条 和竖黑条共有多少个 注意1*1的情况 如果横向纵向都是1*1 算为一个 否则不算 用了下vector  枚举找下 #include <iostream> ...

  8. poj 1364 King(差分约束)

    题目:http://poj.org/problem?id=1364 #include <iostream> #include <cstdio> #include <cst ...

  9. 谈谈数据库中MyISAM与InnoDB区别

    MyISAM:这个是默认类型,它是基于传统的ISAM类型,ISAM是Indexed Sequential Access Method (有索引的顺序访问方法) 的缩写,它是存储记录和文件的标准方法.与 ...

  10. .net 测试工具类

    fluentassertions QuickStart  (替换Assert ) https://github.com/dennisdoomen/fluentassertions/wiki   Moq ...