HDU - 5586 Sum(区间增量最大)
题意:将数组A的部分区间值按照函数f(Ai)=(1890*Ai+143)mod10007修改值,区间长度可以为0,问该操作后数组A的最大值。
分析:先求出每个元素的增量,进而求出增量和。通过b[r]-b[l-1]求区间增量和,枚举r,而b[l-1]则是b[r]前所有元素的最小值,注意mi初始化为0,因为当前有可能的最优值为区间0~r。
#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
typedef long long ll;
typedef unsigned long long llu;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const ll LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {, , -, , -, -, , };
const int dc[] = {-, , , , -, , -, };
const int MOD = 1e9 + ;
const double pi = acos(-1.0);
const double eps = 1e-;
const int MAXN = 1e5 + ;
const int MAXT = + ;
using namespace std;
int a[MAXN];
int b[MAXN];
int main(){
int n;
while(scanf("%d", &n) == ){
memset(a, , sizeof a);
memset(b, , sizeof b);
int ans = ;
for(int i = ; i < n; ++i){
scanf("%d", &a[i]);
ans += a[i];
b[i] = ((a[i] * + ) % ) - a[i];//增量
}
for(int i = ; i < n; ++i){
b[i] += b[i - ];//增量和
}
int ma = ;
int mi = ;
for(int i = ; i < n; ++i){
ma = Max(ma, b[i] - mi);
mi = Min(mi, b[i]);
}
printf("%d\n", ans + ma);
}
return ;
}
HDU - 5586 Sum(区间增量最大)的更多相关文章
- 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 最大子段和
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(dp+技巧)
Problem Description There )mod10007.After that,the sum of n numbers should be as much as possible.Wh ...
- hdu 5586 Sum 基础dp
Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Desc ...
- HDU 5726 GCD 区间GCD=k的个数
GCD Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submis ...
- HDOJ(HDU).1258 Sum It Up (DFS)
HDOJ(HDU).1258 Sum It Up (DFS) [从零开始DFS(6)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双 ...
- HDU 1231 最大连续子序列 &&HDU 1003Max Sum (区间dp问题)
C - 最大连续子序列 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...
- HDU 5586 (dp 思想)
Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submis ...
随机推荐
- jquery使用css函数设置背景色无效解决办法
外部的css样式为: #imageArea{ width: 200px; height: 300px; background-color: #eee !important; } 通过 以下代码来修改其 ...
- codeforces 962 F Simple Cycles Edges
求简单环,即求点=边数的点双分量,加上判断点和边的模板即可 (简单环模板,区分与点双缩点) ; ], edgecnt, dfn[maxm], low[maxm], bcc_cnt, bccnum[ma ...
- 「SP2713」GSS4 - Can you answer these queries IV
传送门 Luogu 解题思路 区间开方以及区间求和. 考虑用线段树来做. 开方操作看似没有任何结合律可言,但这题有另外一个性质: 一个数的初始值不超过 \(10^{18}\) ,而这个数被开方6次左右 ...
- Git如何合并Commit
如果你在 push 你的修改之前想要将本地多次修改后的 commit 合并一下变得更好看,可以使用下面的方法. 指定你要合并的 commit 相关的命令有两种 你可以通过指定修改过去的几个 commi ...
- 吴裕雄--天生自然JAVA数据库编程:CallableStatement接口
DELIMITER // DROP PROCEDURE myproc // -- 删除过程 CREATE PROCEDURE myproc(IN p1 int,INOUT p2 int,OUT p3 ...
- OBS Studio 24.0 RC1 发布 – 有大惊喜
导读 对于那些使用OBS Studio进行跨平台直播和屏幕录制需求的人来说,OBS Studio 24.0即将推出,但首先发布的是他们的候选版本,以审查进入这一重大更新的新功能. OBS Studio ...
- 【pwnable.tw】 alive_note
突然发现已经两个月没写过WP了,愧疚- -... 此题也算一道分数很高的题目,主要考察Shellcode的编写. 又是一道题目逻辑很简单的题. 首先提供了三个函数 查看,删除,添加 查看函数: 此函数 ...
- 08.swoole学习笔记--异步tcp客户端
<?php //创建异步tcp客户端 $client=new swoole_client(SWOOLE_SOCK_TCP,SWOOLE_SOCK_ASYNC); //注册连接成功的回调函数 $c ...
- Excel中列宽、行高与像素的换算公式
DPI Scale ColumnWidth RowHeight 72dpi 75% cw=(pix-5)/6 ...
- [题解] UVA11426 GCD - Extreme (II)
题面 莫反是不可能莫反的,这辈子都不可能莫反了 题目要求的是 \[ \sum\limits_{i=1}^n \sum\limits_{j=i+1}^n \gcd(i,j) \] 稍微变个亚子 \[ \ ...