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≤105)
Next line contains n integers A1,A2....An.(0≤Ai≤104)
It's guaranteed that ∑n≤106.
10000 9999
5
1 9999 1 9999 1
22033
dp[i][0]=dp[i-1][0]+a[i];
dp[i][1]=max(dp[i-1][1]+b[i],dp[i-1][0]+b[i]);
dp[i][2]=max(dp[i-1][2]+a[i],dp[i-1][1]+a[i]);
b=f(a);
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
#define bug(x) cout<<"bug"<<x<<endl;
const int N=1e5+,M=1e6+,inf=;
const ll INF=1e18+,mod=;
ll a[N],b[N],dp[N][];
int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i=;i<=n;i++)
scanf("%d",&a[i]),b[i]=(*a[i]+)%;
dp[][]=dp[][]=dp[][]=;
for(int i=;i<=n;i++)
{
dp[i][]=dp[i-][]+a[i];
dp[i][]=max(dp[i-][]+b[i],dp[i-][]+b[i]);
dp[i][]=max(dp[i-][]+a[i],dp[i-][]+a[i]);
}
printf("%lld\n",max(dp[n][],max(dp[n][],dp[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+技巧)
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]- ...
- HDU 1003 Max Sum --- 经典DP
HDU 1003 相关链接 HDU 1231题解 题目大意:给定序列个数n及n个数,求该序列的最大连续子序列的和,要求输出最大连续子序列的和以及子序列的首位位置 解题思路:经典DP,可以定义 ...
- hdu 4055 Number String (基础dp)
Number String Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- 基础dp
队友的建议,让我去学一学kuangbin的基础dp,在这里小小的整理总结一下吧. 首先我感觉自己还远远不够称为一个dp选手,一是这些题目还远不够,二是定义状态的经验不足.不过这些题目让我在一定程度上加 ...
- hdu 2296 aC自动机+dp(得到价值最大的字符串)
Ring Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
随机推荐
- [kx]人眼结构&凹/凸透镜成像及生活应用
物理学中的lamba光谱: http://www.cnblogs.com/iiiiiher/diary/2018/04/05/8724339.html 思路: 电磁光谱-->可见光-->人 ...
- 分布式文件系统ceph快速部署
架构图 配置ceph-deploy节点 管理节点配置ceph yum源 vim /etc/yum.repos.d/ceph.repo [ceph-noarch] name=Ceph noarch pa ...
- [LeetCode] 285. Inorder Successor in BST_Medium tag: Inorder Traversal
Given a binary search tree and a node in it, find the in-order successor of that node in the BST. No ...
- C#实现无标题栏窗体点击任务栏图标正常最小化或还原的解决方法
对于无标题栏窗体,也就是FormBorderStyle等于System.Windows.Forms.FormBorderStyle.None的窗体,点击任务栏图标的时候,是不能象标准窗体那样最小化或还 ...
- 机器学习理论基础学习9--- EM 算法
EM算法的适用场景: EM算法用于估计含有隐变量的概率模型参数的极大似然估计,或者极大后验概率估计. 当概率模型既含有观测值,又含有隐变量或潜在变量时,就可以使用EM算法来求解概率模型的参数. 当概率 ...
- 7.4 Models -- Pushing Records into the Store
一.概述 1. store是作为一个所有records的缓存,这些records已经被你的应用程序加载.在你的app中如果你的路由或者一个controller请求一条record,如果它在缓存中这个s ...
- cheng gong de daima
/** * Copyright (c) 2012-2016 ebizwindow, Inc. All rights reserved. * * Permission is hereby granted ...
- 【笔记】DataTable或IList使用GroupBy方法的lamda表达式
DataTable GroupBy的用法 var result = dt.AsEnumerable(). GroupBy(g => new { StaffID = g.Field<stri ...
- Python: 正则表达式匹配多行,实现多行匹配模式
1) 点 (.)去匹配任意字符的时候,不能匹配换行符 在这个模式中(?:.|\n)是指定了一个非捕获组(仅仅用来做匹配,部能通过单独捕获或者编号的组) 2) re.DOTALL re.compile( ...
- json-lib基础
一.json-lib所需的jar包: json-lib.jar,commons-beanutils.jar,commons-collections.jar,commons-lang.jar,commo ...