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<iostream>
#include <string>
#include <algorithm>
using namespace std;
long long a[100005],b[100005],sum;
int main()
{
int n,m,i,j,k;
while(cin>>n)
{ sum=0;
for(i=1;i<=n;i++)
{cin>>a[i];
b[i]=(1890*a[i]+143)%10007-a[i];
sum+=a[i];
}
b[0]=0;
for(i=1;i<=n;i++)
b[i]=max(b[i],b[i-1]+b[i]);
sort(b,b+n+1);
cout<<sum+b[n]<<endl;
}
return 0;
}

hdu 5586 sum的更多相关文章

  1. hdu 5586 Sum【dp最大子段和】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5586 Sum Time Limit: 2000/1000 MS (Java/Others)    Me ...

  2. hdu 5586 Sum 最大子段和

    Sum Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5586 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. hdu 5586 Sum 基础dp

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

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

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

  6. HDOJ(HDU).1258 Sum It Up (DFS)

    HDOJ(HDU).1258 Sum It Up (DFS) [从零开始DFS(6)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双 ...

  7. HDU 5586 (dp 思想)

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

  8. hdu 1258 Sum It Up(dfs+去重)

    题目大意: 给你一个总和(total)和一列(list)整数,共n个整数,要求用这些整数相加,使相加的结果等于total,找出所有不相同的拼凑方法. 例如,total = 4,n = 6,list = ...

  9. 数论 --- 费马小定理 + 快速幂 HDU 4704 Sum

    Sum Problem's Link:   http://acm.hdu.edu.cn/showproblem.php?pid=4704 Mean: 给定一个大整数N,求1到N中每个数的因式分解个数的 ...

随机推荐

  1. noip2015运输计划

    二分+LCA+查分前缀和 #include<iostream> #include<cstring> #include<cstdio> #include<alg ...

  2. Linux下MySQL的彻底卸载和安装配置字符集

    前言: Linux环境下MySQL的安装和配置在网上已经有很多教程了.之所以写这篇文章是因为在配置字符集的时候找了网上的一些教程发现并不能用导致折腾了一阵子.下面的教程均是亲自实践. MySQL的彻底 ...

  3. discuz 使模板中的函数不解析 正常使用

    <!--{if $_GET['zcdw']=="baxi"}--><!--{eval $duiwuxinxi = "巴西队";}-->& ...

  4. [转]IBInspectable / IBDesignable

    原文:http://www.cocoachina.com/ios/20150227/11202.html 无论陈词滥调多少次,比起一个需要我们记住并且输入什么的界面来说,如果替换成我们能够看见并可控制 ...

  5. 回收带Lob字段表占用的空间

    SQL> select object_name from user_objects; no rows selected SQL> select segment_name from user ...

  6. NOI2012 骑行川藏

    http://www.lydsy.com/JudgeOnline/problem.php?id=2876 表示完全不会...... 还是跪拜大神吧 http://www.cnblogs.com/Ger ...

  7. 免费 Bootstrap 管理后台模块下载

    在这文章中我们将分享17+个最好的免费 Bootstrap 管理模板.你可以免费下载这些Twitter bootstrap 框架来开发网站后台. SB Admin 2 SB Admin is a fr ...

  8. Centos 添加Root用户

    今天,我要描述的是如何在Centos Linux 系统中建立一个和Root账户等权限的用户账户.废话不多说,开始列出必要的操作. 1:首先,我们使用以下命令 进行用户的创建 和 用户密码的初始化. # ...

  9. 为什么Nginx的性能要比Apache高很多?

    为什么Nginx的性能要比Apache高很多? 这得益于Nginx使用了最新的epoll(Linux 2.6内核)和kqueue(freebsd)网络I/O模型,而Apache则使用的是传统的sele ...

  10. MyBatis映射文件的resultMap如何做表关联

    MyBatis的核心是其映射文件,SqlMap文件,里面配置了项目中用到了什么SQL语句,和数据库相关的逻辑都在这个映射文件里.顾名思义,映射文件就是对Java对象和SQL的映射.这里简单介绍一下映射 ...