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 ...
随机推荐
- Gson的两种解析用法
第一种. 常见的解析,直接将json字符串解析为对应的类. public JavaBean getJsonString(String jsonString) { Gson gson = new Gso ...
- (Power Strings)sdutoj2475
#include <stdio.h>#include <string.h>#include <stdlib.h>char a[1000001];int next[1 ...
- PAT 1045 Favorite Color Stripe[dp][难]
1045 Favorite Color Stripe (30)(30 分) Eva is trying to make her own color stripe out of a given one. ...
- Linux文本编辑器快捷方式
- selenium WebDriver处理文件下载
下载文件WebDriver 允许我们设置默认的文件下载路径.也就是说文件会自动下载并且存在设置的那个目录中.下面以FireFox 为例执行文件的下载. package com.mypro.jase; ...
- SpringMyBatisDay03
1.Spring MVC 1)什么是Spring MVC Spring MVC是Spring框架中一个模块,实现MVC结构,便于简单,快速开发MVC结构的WEB应用,Spring MVC提供的API封 ...
- Hdu dp
4856 这题说的是给了一个图 这个图有很多的隧道每个隧道是单向的 只能从一个入口进入从另一个入口出来 要求计算出走完这些隧道花的总时间 因为这个图是一个网格行的然后 先用bfs算出隧道的出口到每个隧 ...
- MyBatis学习笔记(三)——优化MyBatis配置文件中的配置
转自孤傲苍狼的博客:http://www.cnblogs.com/xdp-gacl/p/4264301.html 一.连接数据库的配置单独放在一个properties文件中 之前,我们是直接将数据库的 ...
- IO(字符流)
1. 由于Java采用16位的Unicode字符,因此需要基于字符的输入/输出操作.从Java1.1版开始,加入了专门处理字符流的抽象类Reader和Writer,前者用于处理输入,后者用于处 ...
- Python之路----迭代器与生成器
一.迭代器 L=[1,,2,3,4,5,] 取值:索引.循环for 循环for的取值:list列表 dic字典 str字符串 tuple元组 set f=open()句柄 range() enumer ...