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

HINT

题意

给你n个数,你可以使得一个区间的数由a[i]变成b[i],b[i] = (1890*a[i]+143)mod10007,问你答案最大为多少

题解:

将b[i]减去a[i],然后跑一个最大子段和就好了

可以dp,也可以尺取法

代码:

#include<iostream>
#include<stdio.h>
#include<cstring>
using namespace std;
#define maxn 100005
long long a[maxn];
long long b[maxn];
long long sumb[maxn];
long long get(long long x)
{
return (*x+)%;
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
memset(a,,sizeof(a));
memset(b,,sizeof(b));
long long sum = ;
for(int i=;i<=n;i++)
{
scanf("%I64d",&a[i]);
sum += a[i];
}
for(int i=;i<=n;i++)
{
b[i]=get(a[i])-a[i];
}
long long Tmp = , tmp = ;
for(int i = ; i <= n ; ++ i)
{
if(tmp + b[i] < )
{
Tmp = max(Tmp , b[i]);
Tmp = max(Tmp , tmp);
tmp = ;
}
else
{
tmp += b[i];
Tmp = max(Tmp,tmp);
}
}
printf("%I64d\n",sum+Tmp);
}
}

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

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

  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 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submiss ...

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

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

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

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

  8. HDU 1003 最大连续子段和

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

  9. HDU 5586 (dp 思想)

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

随机推荐

  1. css的框架——global.css

    global.css,一般这个css文件是用于装全站主要框架css样式代码. “global”翻译为全局.全部.从翻译中大家也能理解global.css用于做什么.大站常常用于装全站公共的CSS样式选 ...

  2. c# List<int> 转 string 以及 string [] 转 List<int>

    List<int> 转 string : list<int>: 1,2,3,4,5,6,7  转换成字符串:“1,2,3,4,5,6,7” List<int> li ...

  3. linux编程获取本机网络相关参数

    getifaddrs()和struct ifaddrs的使用,获取本机IP 博客分类: Linux C编程   ifaddrs结构体定义如下: struct ifaddrs { struct ifad ...

  4. CAKeyframeAnimation

    之所以叫做关键帧动画是因为,这个类可以实现,某一属性按照一串的数值进行动画,就好像制作动画的时候一帧一帧的制作一样. 一般使用的时候  首先通过 animationWithKeyPath 方法 创建一 ...

  5. <转>Python3.x和Python2.x的区别介绍

    1.性能Py3.0运行 pystone benchmark的速度比Py2.5慢30%.Guido认为Py3.0有极大的优化空间,在字符串和整形操作上可以取得很好的优化结果.Py3.1性能比Py2.5慢 ...

  6. asp.net 常用的几种调用存储过程的方法

    (1)简单的无参数存储过程 create procedure ExpOneasselect top 10 * from Corpgo C#调用此存储过程        SqlConnection co ...

  7. 常用SQL语句汇总整理

    1.SQL 插入语句得到自动生成的递增ID 值 insert into Table1(Name,des,num) values (''ltp'',''thisisbest'',10); select ...

  8. LeetCode题解——Unique Path(DP与优化)

    题目:A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). ...

  9. WeChat Official Account Admin Platform API Introduction

    Keyword: WeChat API Introduction Message and GeneralAuthor: PondBay Studio[WeChat Developer EXPERT] ...

  10. How do I use SOCKS proxy in delphi?

    TCP====== For Indy 8.0 In Delphi, do the following: IdTCPClient1.SocksInfo.Host := [the DNS name of ...