hdu-5586 Sum(dp)
题目链接:
Sum
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
First line of each case contains a single integer n.(1≤n≤10^5)
Next line contains n integers A1,A2....An.(0≤Ai≤10^4)
It's guaranteed that ∑n≤10^6.
//#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <cstring>
#include <algorithm>
#include <cstdio> using namespace std;
#define Riep(n) for(int i=1;i<=n;i++)
#define Riop(n) for(int i=0;i<n;i++)
#define Rjep(n) for(int j=1;j<=n;j++)
#define Rjop(n) for(int j=0;j<n;j++)
#define mst(ss,b) memset(ss,b,sizeof(ss));
typedef long long LL;
template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<''||CH>'';F= CH=='-',CH=getchar());
for(num=;CH>=''&&CH<='';num=num*+CH-'',CH=getchar());
F && (num=-num);
}
int stk[], tp;
template<class T> inline void print(T p) {
if(!p) { puts(""); return; }
while(p) stk[++ tp] = p%, p/=;
while(tp) putchar(stk[tp--] + '');
putchar('\n');
} const LL mod=1e9+;
const double PI=acos(-1.0);
const LL inf=1e14;
const int N=1e4+;
const int maxn=; int p[*N],a[*N];
LL dp[*N];
int main()
{
int n;
while(cin>>n)
{
LL sum=,ans=;
Riep(n)read(a[i]),p[i]=(*a[i]+)%-a[i],sum=sum+a[i];
dp[]=;
for(int i=;i<=n;i++)
{
if(dp[i-]+p[i]<)dp[i]=;
else dp[i]=dp[i-]+p[i];
ans=max(ans,dp[i]);
}
cout<<sum+ans<<"\n";
} 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(dp+技巧)
Problem Description There )mod10007.After that,the sum of n numbers should be as much as possible.Wh ...
- 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 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个 ...
- hdu 4507 数位dp(求和,求平方和)
http://acm.hdu.edu.cn/showproblem.php?pid=4507 Problem Description 单身! 依旧单身! 吉哥依旧单身! DS级码农吉哥依旧单身! 所以 ...
随机推荐
- CentOS6 下Vim安装和配置
1.系统只安装了vim-minimal,执行以下命令安装另外两个组件 yum install vim-common yum install vim-enhanced 2.安装ctags yum ins ...
- JavaScript谁动了你的代码
到目前为止,同学你知道了JavaScript的历史,也了解其"你想是啥就是啥"的变量系统.相信凭借你深厚的Java或者C++功底,再加上程序员特有的自傲气质,你肯定会信心满满:自信 ...
- PostgreSQL中使用枚举类型
https://wiki.postgresql.org/wiki/Enum 建立enum: pgsql=# CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy' ...
- WEB前端性能优化小结
转:http://www.gafish.net/archives/1514 对前端开发工程师来说,前端性能优化的重要性是不言而喻的,最为大家所知的是YSLOW的23条优化规则,在我的理解中,性能优化不 ...
- IE6文字溢出BUG(多出来的猪问题)
在IE6下使用浮动可能会出现文字重复的情况. 在IE6下,浮动层之间有注释文字的话,之前那个浮动层的内容文字就有可能遭遇一个“隐形”的复制,但是代码里查看文字可并没有多出来. 看个例子: HTML & ...
- CSDN问答频道“华章杯”7月排行榜活动开始,丰厚奖品等你拿
CSDN问答频道月度排行榜,是CSDN问答频道从3月开始举办的活动,旨在鼓励更多用户参与提问和解答,创造一个良好的互帮互助氛围,使参与者在问和答的过程中得到技术水平的提升,也希望大家能在技术交流中结交 ...
- HttpRequest类
一.HttpRequest的作用 HttpRequest的作用是令到Asp.net能够读取客户端发送HTTP值.比如表单.URL.Cookie传递过来的参数. 返回字符串的那些值就不说了,那些基本上都 ...
- Codeforces Round #311 (Div. 2) A. Ilya and Diplomas 水题
A. Ilya and Diplomas Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/557/ ...
- TP复习10
i * { padding:0; margin:0; } 居中 ## ThinkPHP 3.1.2 模板中的变量#讲师:赵桐正微博:http://weibo.com/zhaotongzheng 本节课 ...
- [Angular 2] Angular 2 Smart Components vs Presentation Components
Both Smart Components and Presentation Components receive data from Services in entirely different w ...