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. kettle_简单入门

    简介 Kettle是一款纯Java开发的ETL工具,它是跨平台的,所以它可以在Window.Linux.Unix上运行.注意什么是ETL,读者可以自行百度了解,我的理解是将一个数据库的数据导入到另外一 ...

  2. 使用getid3获取音频文件信息

    今天有个需求,在上传音频文件时候自动获取音频的秒数,和大家分享一下. 首先把getid3的包下载下来 链接:https://pan.baidu.com/s/1Qmdj-I4boz9Sm9GFsON0D ...

  3. JS里点击事件判断是否 触发了节点 和给标签添加class属性

    $("#activityType").click(function(e){ if(e.target==$("#bb")[0]){ var bb=document ...

  4. java对json文件的操作

    第一步:通过FileReader读取json文件第二步:使用BufferReader,先通过I/O读取一定大小的数据缓存到数组中,然后再从数组取出数据.第三步:用一个字符串把每次传来的数据处理后写到新 ...

  5. Tensorflow - Implement for generating some 3-dimensional phony data and fitting them with a plane.

    Coding according to TensorFlow 官方文档中文版 import tensorflow as tf import numpy as np ''' Intro. for thi ...

  6. Reject Inference: Your Data is Deceiving You

    Keyword: Reject Inference Suppose there is a dataset of several attributes, including working condit ...

  7. 1.编译azkaban

    1.下载azkaban的源码 https://github.com/azkaban/azkaban.git 然后解压得到azkaban-master.zip,解压:unzip azkaban-mast ...

  8. C语言文件进阶操作

    Description文件a.dic.b.dic.c.dic中分别存有张三的三科成绩,每个文件都是16字节:前8个字节存储其英文名字zhangsan,后面是一个空格,其后的2个字节存储其年龄(文本方式 ...

  9. Repair the Wall (贪心)

    Long time ago , Kitty lived in a small village. The air was fresh and the scenery was very beautiful ...

  10. 内存转储文件调试系统崩溃bug

    百度百科:内存转储文件 内存转储是用于系统崩溃时,将内存中的数据转储保存在转储文件中,供给有关人员进行排错分析用途.而它所保存生成的文件就叫做内存转储文件. 内存转储文件也被称作虚拟内存,它是用硬盘里 ...