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个 ...
随机推荐
- GDAL的RASTERIO功能
为了能快速的显示大影像,最近一直在学习GDAL,GDAL确实是一个功能强大的开源库,其核心部分数据集和波段,下面这个图很详细的描述了它们之间的关系,还有其中的细节: GDAL ...
- logcat错误日志
http://www.crifan.com/android_log_to_file/ http://www.iteye.com/problems/85431 http://www.cnblogs.co ...
- JVM 看不到某些异常的stacktrace问题(转)
在java 1.5的release notes里面可以看到这样一句话: The compiler in the server VM now provides correct stack backtra ...
- 知道版本对于出0day后批量攻击dedecms有非常大的帮助,先判断版本再选择相应exp,效率大增
需要知道织梦网站版本URL路径后面添加/data/admin/ver.txt 例如:http://www.dedecms.com/data/admin/ver.txt 20100708是最新版本5.6 ...
- 数据挖掘之分类算法---knn算法(有matlab例子)
knn算法(k-Nearest Neighbor algorithm).是一种经典的分类算法.注意,不是聚类算法.所以这种分类算法 必然包括了训练过程. 然而和一般性的分类算法不同,knn算法是一种懒 ...
- .NET与你若仅仅如初见(一)
难忘初次见到你,那是一个夏日的午后,可是天空中乌云密布.大雨来临前的一段时间总是非常闷热的,当我朦胧的睡眼看到你之后瞬间就清醒了,感觉空气也凉爽了起来.尽管仅仅一眼但就是被你那清新脱俗沉鱼落雁之美所征 ...
- 【main()的参数探究】
恩...今天研究信安的课件的时候看到一段对于main(int argc,char *argv[])的编程 所以探究探究main()函数的参数 探究程序如下: #include <cstdio&g ...
- jmx使用应该注意的基本规范
1.标准MBean 名称必需是在要监控的类名后面加上“MBean ”. 2.监控的类和MBean 接口必需在同一包下,也可以理解为注册的接口名字必须以MBean结尾,接口实现类比接口名字少了MBean ...
- MatLab实现FFT与功率谱
FFT和功率谱估计 用Fourier变换求取信号的功率谱---周期图法 clf; Fs=1000; N=256;Nfft=256;%数据的长度和FFT所用的数据长度 n=0:N-1;t=n/Fs;%采 ...
- hibernate 之 HQL语句总结【转】
1. 查询整个映射对象所有字段 //直接from查询出来的是一个映射对象,即:查询整个映射对象所有字段 String hql = "from Users"; Query query ...