Sum

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 507    Accepted Submission(s): 284

Problem Description
There is a number sequence A1,A2....An

,A1,A2....An

,A1,A2....An

,A1,A2....An

,A1,A2....An

,A1,A2....An

,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
 
Source
 
传送门 http://acm.hdu.edu.cn/showproblem.php?pid=5586
类似杭电1003
题意  一串序列 可以只能更改一个区间 或不更改f(x)=(1890x+143)mod10007    更改操作为f(x)=(1890x+143)mod10007
询问 这串序列的和的最大值
做一个变形 每个值变为 f(x)-x 然后按照1003的方法 求最大连续区间的和 
dp[i]=max(dp[i],dp[i-1]+dp[i]);
 
f(x)=(1890x+143)mod10007
 
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n;
int bac(int s)
{
return (1890*s+143)%10007;
}
int b[100005],a[100005];
int main()
{
while(scanf("%d",&n)!=EOF)
{
memset(b,0,sizeof(b));
memset(a,0,sizeof(a));
int re=0;
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
re=re+a[i];
b[i]=bac(a[i])-a[i];
}
// int exm=0;
int maxn=0;
for(int i=1;i<n;i++)
{
if(b[i]+b[i-1]>b[i])
b[i]=b[i]+b[i-1];
if(b[i]>maxn)
maxn=b[i]; }
printf("%d\n",re+maxn);
}
return 0;
}

HDU 5586 (dp 思想)的更多相关文章

  1. hdu 3030 Increasing Speed Limits (离散化+树状数组+DP思想)

    Increasing Speed Limits Time Limit: 2000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java ...

  2. hdu 3016 dp+线段树

    Man Down Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total S ...

  3. HDU 5928 DP 凸包graham

    给出点集,和不大于L长的绳子,问能包裹住的最多点数. 考虑每个点都作为左下角的起点跑一遍极角序求凸包,求的过程中用DP记录当前以j为当前末端为结束的的最小长度,其中一维作为背包的是凸包内侧点的数量.也 ...

  4. 到底什么是dp思想(内含大量经典例题,附带详细解析)

    期末了,通过写博客的方式复习一下dp,把自己理解的dp思想通过样例全部说出来 说说我所理解的dp思想 dp一般用于解决多阶段决策问题,即每个阶段都要做一个决策,全部的决策是一个决策序列,要你求一个 最 ...

  5. DP思想在斐波那契数列递归求解中的应用

    斐波那契数列:1, 1, 2, 3, 5, 8, 13,...,即 f(n) = f(n-1) + f(n-2). 求第n个数的值. 方法一:迭代 public static int iterativ ...

  6. hdu 4612 Warm up 双连通+树形dp思想

    Warm up Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Total S ...

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

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

  8. HDU 2227 Find the nondecreasing subsequences dp思想 + 树状数组

    http://acm.hdu.edu.cn/showproblem.php?pid=2227 用dp[i]表示以第i个数为结尾的nondecreasing串有多少个. 那么对于每个a[i] 要去找 & ...

  9. hdu 4521 小明序列(线段树,DP思想)

    题意: ①首先定义S为一个有序序列,S={ A1 , A2 , A3 , ... , An },n为元素个数 : ②然后定义Sub为S中取出的一个子序列,Sub={ Ai1 , Ai2 , Ai3 , ...

随机推荐

  1. 浪在ACM新春大作战

    题目链接: # Name 补题状态 A Memory and Crow 已补 B Memory and Trident 已补 C Memory and De-Evolution 已补 D Memory ...

  2. eos开发指南

    十分钟教你开发EOS智能合约 在CSDN.柏链道捷(PDJ Education).HelloEOS.中关村区块链产业联盟主办的「EOS入门及最新技术解读」专场沙龙上,柏链道捷(PDJ Educatio ...

  3. .Net并行编程 - 并行任务基础知识

    在微软的.NET Framework中,任务是通过System.Threading.Tasks命令空间中的Task类来实现的.它的静态属性Task.Factory是TaskFactory类的一个实例, ...

  4. [git] Git in Practice

    Work flow with git and github Work with Remotes Check the current status git status Check the latest ...

  5. Python高级编程-多进程

    要让Python程序实现多进程(multiprocessing),我们先了解操作系统的相关知识. Unix/Linux操作系统提供了一个fork()系统调用,它非常特殊.普通的函数调用,调用一次,返回 ...

  6. nodejs在linux环境下安装更新方式

    #检查是否已经安装 rpm -qa | grep python #查版本 python #最好是重新安装 Python推荐版本( >= v2.5.0 & < 3.0.0 ),否则影 ...

  7. Oracle ORA-12541:TNS:no listener错误解决方法 (转)

    前天装好的Oracle,昨天突然不好用了,从Oracle的错误提示来看,是说TNS:no listener ,估计是某种服务没有启动,打开windows管理工具->服务,一看,有一个Oracle ...

  8. unity 学习记录

    世界第九条约定 缘起 嗯,其实一开始我知道unity是个弄游戏的,也知道好像神庙逃亡,炉石都是出自unity,然后舍友都报了,我也觉得这个东西挺高大上的,所以忍不住自己的双手,报了名,确实,这能学到很 ...

  9. Web后台任务处理

    文章:.NET Core开源组件:后台任务利器之Hangfire Hangfire官网介绍:在.NET和.NET Core应用程序中执行后台处理的简便方法.无需Windows服务或单独的过程. 以持久 ...

  10. sping框架(3)— 使用spring容器

    spring有两个核心接口:BeanFactory和ApplicationContext,其中ApplicationContext是BeanFactory的子接口.它们都可以代表spring容器,sp ...