hdu1024(最大m串子序列)
m的范围没给,很坑爹
Max Sum Plus Plus
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 12747 Accepted Submission(s): 4202
Given a consecutive number sequence S1, S2, S3, S4 ... Sx, ... Sn (1 ≤ x ≤ n ≤ 1,000,000, -32768 ≤ Sx ≤ 32767). We define a function sum(i, j) = Si + ... + Sj (1 ≤ i ≤ j ≤ n).
Now given an integer m (m > 0), your task is to find m pairs of i and j which make sum(i1, j1) + sum(i2, j2) + sum(i3, j3) + ... + sum(im, jm) maximal (ix ≤ iy ≤ jx or ix ≤ jy ≤ jx is not allowed).
But I`m lazy, I don't want to write a special-judge module, so you don't have to output m pairs of i and j, just output the maximal summation of sum(ix, jx)(1 ≤ x ≤ m) instead. ^_^
Process to the end of file.
2 6 -1 4 -2 3 -2 3
8
Huge input, scanf and dynamic programming is recommended.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <sstream>
#include <iostream>
using namespace std;
#define INF 0x3fffffff
typedef __int64 LL;
#define N 1000100 LL dp[N][];
LL g[N]; int main()
{
//freopen("//home//chen//Desktop//ACM//in.text","r",stdin);
//freopen("//home//chen//Desktop//ACM//out.text","w",stdout);
int m,n;
while(scanf("%d%d",&m,&n)!=EOF)
{
for(int i=;i<=n;i++)
{
g[i]=-;
dp[i][]=dp[i][]=-;
}
int a=,b=;
for(int i=;i<=n;i++)
{
swap(a,b);
int tmp;
scanf("%d",&tmp);
for(int j=m;j>=;j--)
{
if(j>i) continue;
dp[j][a]=max(dp[j][b],g[j-])+tmp;
if(dp[j][a] > g[j]) g[j] = dp[j][a];
}
}
printf("%I64d\n",g[m]);
}
return ;
}
hdu1024(最大m串子序列)的更多相关文章
- 【BZOJ】2086: [Poi2010]Blocks
题意 \(n(1 \le n \le 1000000)\)个数\(a_i(a_i \le 10^9)\).\(m(1 \le m \le 50)\)次询问,每次给出一个\(k(k \le 10^9)\ ...
- 【HDU4632 Palindrome subsequence】区间dp
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4632 题意:给你一个序列,问你该序列中有多少个回文串子序列,可以不连续. 思路:dp[i][j]表示序 ...
- HDU4632:Palindrome subsequence(区间DP)
Problem Description In mathematics, a subsequence is a sequence that can be derived from another seq ...
- POJ 1458 Common Subsequence (zoj 1733 ) LCS
POJ:http://poj.org/problem?id=1458 ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=73 ...
- Parity game(带权并查集+离散化)
题目链接 //kuangbin 题意: 现在你和你的朋友正在玩一种游戏. 你的朋友写下一串0和1的序列,然后你选择其中一串子序列(如[3,5])并且问他这个序列是包含奇数个1还是偶数个1(和是奇数还 ...
- 数据挖掘入门系列教程(九)之基于sklearn的SVM使用
目录 介绍 基于SVM对MINIST数据集进行分类 使用SVM SVM分析垃圾邮件 加载数据集 分词 构建词云 构建数据集 进行训练 交叉验证 炼丹术 总结 参考 介绍 在上一篇博客:数据挖掘入门系列 ...
- Codeforces Round #661 (Div. 3) D、E1 题解
D. Binary String To Subsequences #贪心 #构造 题目链接 题意 给定一个\(01\)串\(s\),完全分割成若干子序列(注意,不要混淆子串与子序列的概念),其中的子序 ...
- HDU-1024 Max Sum Plus Plus 动态规划 滚动数组和转移优化
题目链接:https://cn.vjudge.net/problem/HDU-1024 题意 给n, m和一个序列,找m个不重叠子串,使这几个子串内元素和的和最大. n<=1e6 例:1 3 1 ...
- 【题解】最大 M 子段和 Max Sum Plus Plus [Hdu1024] [51nod1052]
[题解]最大 M 子段和 Max Sum Plus Plus [Hdu1024] [51nod1052] 传送门:最大 \(M\) 子段和 \(Max\) \(Sum\) \(Plus\) \(Plu ...
随机推荐
- Eclipse删除文件的恢复(转)
与vs不同,在eclipse中删除的文件是不会放进回收站的, 很多人以为eclipse是直接在磁盘删除文件,所以一般都会用反删除软件恢复. 其实不必那么麻烦的,只要对着被删除文件的上一层目录按右键, ...
- 如何用nodejs 开发一个命令行交互工具
参考地址1 参考地址2 一.npm package.json bin 1.package.json { "name": "test", "versio ...
- 温故而知新 forEach 无法中断(break)的问题
forEach无法使用break和return来中断,只能使用throw catch来达到中断的效果了. var id = (function(){ // forEach 是无法中断的.除非用这种ha ...
- Memcached真的过时了吗?
Memcached真的过时了吗? 这两年Redis火得可以,Redis也常常被当作Memcached的挑战者被提到桌面上来.关于Redis与Memcached的比较更是比比皆是.然而,Redis真的在 ...
- Spring Cloud(八):分布式配置中心服务化和高可用
在前两篇的介绍中,客户端都是直接调用配置中心的server端来获取配置文件信息.这样就存在了一个问题,客户端和服务端的耦合性太高,如果server端要做集群,客户端只能通过原始的方式来路由,serve ...
- C# FTP操作类可用
public class FtpClient { #region 构造函数 /// <summary> /// 创建FTP工具 /// <para> /// 默认不使用SSL, ...
- 关于 initWithNibName 和 loadNibNamed 的区别和联系-iPhone成长之路
转自:http://blog.sina.com.cn/s/blog_7b9d64af01018f2u.html 关于 initWithNibName 和 loadNibNamed 的区别和联系.之所以 ...
- FreeRTOS 计数信号量
以下转载自安富莱电子: http://forum.armfly.com/forum.php 本章节开始讲解 FreeRTOS 任务间的同步和资源共享机制,计数信号量. FreeRTOS 中计数信号量的 ...
- Spring MVC添加支持Http的delete、put请求!(HiddenHttpMethodFilter)
浏览器form表单只支持GET与POST请求,而DELETE.PUT等method并不支持,spring3.0添加了一个过滤器,可以将这些请求转换为标准的http方法,使得支持GET.POST.PUT ...
- 使用padding和float处理带有间隙的多块布局
. 每个间隙都是20px <div class="action-content pd10" style=""> <div class=&quo ...