hdu 5586 Sum(dp+技巧)
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?
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.
For each test case,output the answer in a line.
思路:令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+技巧)的更多相关文章
- hdu 5586 Sum【dp最大子段和】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5586 Sum Time Limit: 2000/1000 MS (Java/Others) Me ...
- hdu 5586 Sum 基础dp
Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Desc ...
- hdu 5586 Sum 最大子段和
Sum Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5586 Desc ...
- hdu 5586 sum
Problem Description There is a number sequence A1,A2....An,you can select a interval [l,r] or not,al ...
- HDU - 5586 Sum(区间增量最大)
题意:将数组A的部分区间值按照函数f(Ai)=(1890*Ai+143)mod10007修改值,区间长度可以为0,问该操作后数组A的最大值. 分析:先求出每个元素的增量,进而求出增量和.通过b[r]- ...
- HDOJ(HDU).1003 Max Sum (DP)
HDOJ(HDU).1003 Max Sum (DP) 点我挑战题目 算法学习-–动态规划初探 题意分析 给出一段数字序列,求出最大连续子段和.典型的动态规划问题. 用数组a表示存储的数字序列,sum ...
- hdu 3709 数字dp(小思)
http://acm.hdu.edu.cn/showproblem.php?pid=3709 Problem Description A balanced number is a non-negati ...
- HDU 2836 (离散化DP+区间优化)
Reference:http://www.cnblogs.com/wuyiqi/archive/2012/03/28/2420916.html 题目链接: http://acm.hdu.edu.cn/ ...
- hdu 3507 斜率dp
不好理解,先多做几个再看 此题是很基础的斜率DP的入门题. 题意很清楚,就是输出序列a[n],每连续输出的费用是连续输出的数字和的平方加上常数M 让我们求这个费用的最小值. 设dp[i]表示输出前i个 ...
随机推荐
- vmware配置安装JDK、Tomcat以及项目部署
1.安装JDK1.7 JDK:http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html 安 ...
- BPM7.5.1升级细节,万事开头难
背景:Linux5.9,BPM 7.5.0集群环境,内置WAS ND7.0.0.17 详情见上图 故障现象:升级BPM 7.5.1集群环境 1,按照 IBM 信息中心步骤,升级BPM需下载相应补丁 包 ...
- mma ctf 1st && csaw 2015
(很久以前做的,现在发一下)最近做了两个CTF,水平太渣,做了没几道题,挑几个自己做的记录一下. mma ctf 1st 之 rps: from socket import * s = socket( ...
- 【枚举+贪心】【TOJ3981】【ICPC Balloons】
给你N种不同颜色气球,每种气球有个数目 count[i],给的同种颜色气球可能是L尺寸,或M尺寸. M个问题,每个问题有个解决人数ac[i]. 每个问题 要分配一种颜色的气球,尺寸要一样 现在 这些气 ...
- 【最大流】【HDU3338】【Kakuro Extension】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3338 题目大意:填数字,使白色区域的值得和等于有值得黑色区域的相对应的值,用网络流来做 题目思路:增加 ...
- 【奇偶剪枝】【HDU1010】Tempter of the Bone
题意:输入一个n*m的迷宫,和一个T:可以在迷宫中生存的最大时间.S为起点,D为终点.并且,每个格子只能踩一次,且只能维持一秒,然后该块地板就会塌陷.所以你必须每秒走一步,且到D点时,所用时间为T. ...
- Kafka的可靠性问题
a. Producer到broker 把request.required.acks设为1,丢会重发,丢的概率很小 b. Broker b.1 对于broker,落盘的数据,除非磁盘坏了,不会丢的 b. ...
- spring boot + velocity中文乱码解决方式
在application.properties文件中,加入如下配置: spring.velocity.properties.input.encoding=UTF-8spring.velocity.pr ...
- js 将网页内容生成图片
$(function () { $("#saveimg_btn").on("click",function (event) { event.preventDef ...
- Zepto.js touch模块深入分析 解决手机点击事件
源码: // Zepto.js // (c) 2010-2015 Thomas Fuchs // Zepto.js may be freely distributed under the MIT li ...