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+)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.(≤n≤)
Next line contains n integers A1,A2....An.(≤Ai≤)
It's guaranteed that ∑n≤106.

 
Output
For each test case,output the answer in a line.
Sample Input

Sample Output

 
Source

思路:令Ai=f(Ai)-Ai,然后求一遍最大连续子序列和就能知道最多能增加的值。

       一开始统计所有数的和ans,再加上最多增加的值就是答案了。

 #pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<stdlib.h>
#include <stack>
using namespace std;
#define PI acos(-1.0)
#define max(a,b) (a) > (b) ? (a) : (b)
#define min(a,b) (a) < (b) ? (a) : (b)
#define ll long long
#define eps 1e-10
#define MOD 1000000007
#define N 100006
#define inf 1e12
int n;
int a[N];
int A[N];
int main()
{
while(scanf("%d",&n)==){
int ans=;
for(int i=;i<n;i++){
scanf("%d",&a[i]);
ans+=a[i];
}
for(int i=;i<n;i++){
A[i]=(a[i]*+)%-a[i];
//printf("===%d\n",A[i]);
}
int ThisSum=,MaxSum=;
for(int i=;i<n;i++){
ThisSum+=A[i];
if(ThisSum>MaxSum){
MaxSum=ThisSum;
}else if(ThisSum<){
ThisSum=;
}
}
ans+=MaxSum;
printf("%d\n",ans); }
return ;
}

hdu 5586 Sum(dp+技巧)的更多相关文章

  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 基础dp

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

  3. hdu 5586 Sum 最大子段和

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

  4. hdu 5586 sum

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

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

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

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

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

  7. hdu 3709 数字dp(小思)

    http://acm.hdu.edu.cn/showproblem.php?pid=3709 Problem Description A balanced number is a non-negati ...

  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. jsp 2种include标签的区别

    众所周知,jsp中有2种标签用于包含其他jsp或者文件 1.include指令,其实是java代码 <%@ include file="xxx.jsp"%> 2.jsp ...

  2. 新 Azure SQL 数据库服务等级的性能

    4 月 24 日,我们发布了 SQL Database 基本级(预览版)和标准级(预览版)新服务等级的预览版以及新的业务连续性功能.在本博客文章中,我们将深入探究 SQL Database 中新等级的 ...

  3. flex——dictionary跟Object的区别与遍历

    AS3中Object和 Dictionary都可以用来保存key-value形式的数据,Dictionary类和Object唯一的区别在于:Dictionary对象可以使用非字符串作为键值对的键.例如 ...

  4. Sereja and Coat Rack(水)

    Sereja and Coat Rack Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I6 ...

  5. ZCTF-ARM64-Re300

    Re300-arm64     是一个64位的ARM程序.使用IDA加载,蹦出来这个框框,就是说IDA6.6还没有对ARM64位的程序实现relocation的分析.     就是由于这个,所以连对l ...

  6. oracle修改闪回日志的位置

    改变闪回日志位置的步骤: A.Change the value of the DB_RECOVERY_FILE_DEST initialization parameter to a new value ...

  7. 【最大流】【HDU2883】【kebab】

    题意: 有一个烧烤机,每次最多能烤 m 块肉,现在有 n 个人来买烤肉,每个人到达时间为 si,离开时间为 ei,点的烤肉数量为 ci,点的烤肉所需烘烤时间为 di, 每个人要烤的肉可以分成若干份在同 ...

  8. Android编译错误——undefined reference to

    [错误描述] 未定义引用 提示如下:bootable/recovery/minzip/Zip.c:1122: error: undefined reference to 'selabel_lookup ...

  9. knockoutjs简单使用

    knockoutjs是一个不错的前端MVVM框架,极大的减轻了前端工作开发量,增加前端代码的维护性.主要特点:声明式绑定.依赖跟踪.模块开速开发. 如下代码(官方代码稍做修改) <p> 姓 ...

  10. Android 内部启动其他应用,以及打开指定qq聊天界面

    在自己应用中打开第三方应用,有好多种方法,这里举例一种: //以打开微信为例,前提需要知道打开应用的包名,一般一个发布版本的应用,包名不会轻易改变的,但是,打开QQ就要注意了,毕竟QQ的发布版本有不下 ...