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

Problem Description
Now I think you have got an AC in Ignatius.L's "Max Sum" problem. To be a brave ACMer, we always challenge ourselves to more difficult problems. Now you are faced with a more difficult problem.

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. ^_^

 
Input
Each test case will begin with two integers m and n, followed by n integers S1, S2, S3 ... Sn.
Process to the end of file.
 
Output
Output the maximal summation described above in one line.
 
Sample Input
1 3 1 2 3
2 6 -1 4 -2 3 -2 3
 
Sample Output
6
8

Hint

Huge input, scanf and dynamic programming is recommended.

 
Author
JGShining(极光炫影)
 
#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串子序列)的更多相关文章

  1. 【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)\ ...

  2. 【HDU4632 Palindrome subsequence】区间dp

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4632 题意:给你一个序列,问你该序列中有多少个回文串子序列,可以不连续. 思路:dp[i][j]表示序 ...

  3. HDU4632:Palindrome subsequence(区间DP)

    Problem Description In mathematics, a subsequence is a sequence that can be derived from another seq ...

  4. 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 ...

  5. Parity game(带权并查集+离散化)

    题目链接  //kuangbin 题意: 现在你和你的朋友正在玩一种游戏. 你的朋友写下一串0和1的序列,然后你选择其中一串子序列(如[3,5])并且问他这个序列是包含奇数个1还是偶数个1(和是奇数还 ...

  6. 数据挖掘入门系列教程(九)之基于sklearn的SVM使用

    目录 介绍 基于SVM对MINIST数据集进行分类 使用SVM SVM分析垃圾邮件 加载数据集 分词 构建词云 构建数据集 进行训练 交叉验证 炼丹术 总结 参考 介绍 在上一篇博客:数据挖掘入门系列 ...

  7. Codeforces Round #661 (Div. 3) D、E1 题解

    D. Binary String To Subsequences #贪心 #构造 题目链接 题意 给定一个\(01\)串\(s\),完全分割成若干子序列(注意,不要混淆子串与子序列的概念),其中的子序 ...

  8. HDU-1024 Max Sum Plus Plus 动态规划 滚动数组和转移优化

    题目链接:https://cn.vjudge.net/problem/HDU-1024 题意 给n, m和一个序列,找m个不重叠子串,使这几个子串内元素和的和最大. n<=1e6 例:1 3 1 ...

  9. 【题解】最大 M 子段和 Max Sum Plus Plus [Hdu1024] [51nod1052]

    [题解]最大 M 子段和 Max Sum Plus Plus [Hdu1024] [51nod1052] 传送门:最大 \(M\) 子段和 \(Max\) \(Sum\) \(Plus\) \(Plu ...

随机推荐

  1. DHCP(动态主机配置协议)工作流程

    一.DHCP的作用 我们先来看一下什么是DHCP,DHCP(Dynamic Host Configuration Protocol,动态主机配置协议)它可以为客户机自动分配IP地址.子网掩码以及缺省网 ...

  2. @Autowired和@Resource装配

    从Spring2.5開始就能够使用注解自己主动装配Bean的属性. 使用注解自己主动装配与XML中使用autowire属性自己主动装配并没有太大区别. Spring容器默认禁用注解装配. 所以在基于注 ...

  3. JSON对象和JSON字符串以及JSON.parse 函数的使用

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. AutoFac文档6(转载)

    目录 开始 Registering components 控制作用域和生命周期 用模块结构化Autofac xml配置 与.net集成 深入理解Autofac 指导 关于 词汇表 实例生命周期 实例生 ...

  5. iptables安装失败后-------------firewalld回归

    yum install firewalld systemctl stop iptables; systemctl mask iptables; systemctl unmask firewalld s ...

  6. [转]__cdecl与__stdcall

    来自Programming Windows 5th Edition The WinMain function is given a type of WINAPI (as is every Window ...

  7. Django Model获取指定列的数据

    model一般都是有多个属性的,但是很多时候我们又只需要查询特定的某一个,这个时候可以用到values和values_list 利用values查询 from attendence.models im ...

  8. jquer WdatePicker 使用 手册

    1. 跨无限级框架显示 无论你把日期控件放在哪里,你都不需要担心会被外层的iframe所遮挡进而影响客户体验,因为My97日期控件是可以跨无限级框架显示的 示例2-7 跨无限级框架演示 可无限跨越框架 ...

  9. ADO.NET数据库应用开发_ExtendedProperties属性

    7.5.5 ExtendedProperties属性 ExtendedProperties属性用来获取存储自定义属性的集合.可以在该属性中增加附加的存储信息.它的扩展属性必须是字符串类型.当以XML的 ...

  10. [usb]usb otg和host

    USB OTG 设备既能做主机,又能做设备.USB HOST是指主机.当OTG 插到 HOST 上,OTG 的角色 就是 device.当device 插到 OTG 上,OTG 的角色就是 HOST. ...