HDU 1024 Max Sum Plus Plus (递推)
Max Sum Plus Plus
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 18653 Accepted Submission(s): 6129
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. ^_^
Process to the end of file.
8
Huge input, scanf and dynamic programming is recommended.
dp[i][j][0] ... 表示前i个数分成j个组,不选第i个数的最大得分
dp[i][j][1] ... 表示前i个数分成j个组,选第i个数的最大得分
因为状态i只跟状态i-1, 所以可以用滚动数组来减空间
取最要自己写 。 否则卡常数会超时
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm> using namespace std ;
const int N = ;
const int inf = 1e9+; int dp[][N][] , n , m , x[N] ;
inline int MAX( int a , int b ) {
if( a > b ) return a ;
else return b ;
}
int main() {
// freopen("in.txt","r",stdin);
while( ~scanf("%d%d",&m,&n) ) {
for( int i = ; i <= n ; ++i ) {
scanf("%d",&x[i]);
}
int v = ;
dp[v][][] = ;
dp[v][][] = x[] ;
for( int i = ; i < n ; ++i ) {
for( int j = ; j <= i + && j <= m ; j++ ) {
dp[v^][j][] = dp[v^][j][] = -inf ;
}
for( int j = min( m , i ) ; j >= ; --j ) {
if( j != i ) {
dp[v^][j+][] = MAX( dp[v][j][] + x[i+] , dp[v^][j+][] );
dp[v^][j][] = MAX( dp[v][j][] , dp[v^][j][]);
}
if( j != ) {
dp[v^][j][] = MAX ( dp[v^][j][] , dp[v][j][] + x[i+] ) ;
dp[v^][j+][] = MAX ( dp[v^][j+][] , dp[v][j][] + x[i+] ) ;
dp[v^][j][] = MAX ( dp[v^][j][] , dp[v][j][] ) ;
}
}
v ^= ;
}
int ans = -inf ;
if( m < n ) ans = MAX( ans , dp[v][m][] );
if( m > ) ans = MAX( ans , dp[v][m][] );
printf("%d\n",ans);
}
return ;
}
HDU 1024 Max Sum Plus Plus (递推)的更多相关文章
- HDU 1024 Max Sum Plus Plus --- dp+滚动数组
HDU 1024 题目大意:给定m和n以及n个数,求n个数的m个连续子系列的最大值,要求子序列不想交. 解题思路:<1>动态规划,定义状态dp[i][j]表示序列前j个数的i段子序列的值, ...
- HDU 1024 Max Sum Plus Plus (动态规划)
HDU 1024 Max Sum Plus Plus (动态规划) Description Now I think you have got an AC in Ignatius.L's "M ...
- HDU 1024 Max Sum Plus Plus(m个子段的最大子段和)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1024 Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/ ...
- HDU 1024 max sum plus
A - Max Sum Plus Plus Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I6 ...
- HDU 1024 Max Sum Plus Plus【动态规划求最大M子段和详解 】
Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- hdu 1024 Max Sum Plus Plus DP
Max Sum Plus Plus Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php ...
- hdu 1024 Max Sum Plus Plus
Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU 1024 Max Sum Plus Plus【DP】
Now I think you have got an AC in Ignatius.L's "Max Sum" problem. To be a brave ACMer, we ...
- HDU 1024 Max Sum Plus Plus(DP的简单优化)
Problem Description Now I think you have got an AC in Ignatius.L's "Max Sum" problem. To b ...
随机推荐
- Java动手动脑02
一.平方数静方法: public class SquareInt { public static void main(String[] args) { int result; for (int x = ...
- 关于反射和动态代理和AOP
package Exercise.reflect; /** * 反射把java中所有的东西都当做对象,甚至是类的本身也作为一种对象,并把它作为Class的对象的实例: * 反射是把类.类的属性.方法都 ...
- Python3 面向对象-类的继承与派生
1.什么是继承? 继承是一种创建新类的方式,新建的类可以继承一个或多个父类(python支持多继承),父类可称为基类或超类,新建的类称为派生类和或子类. 子类会遗传父类的属性,从而解决代码重用问题. ...
- 认识.net Framework
- getCurrentPages
解释:getCurrentPages 全局函数用于获取当前页面栈的实例,以数组形式按栈的顺序给出,第一个元素为首页,最后一个元素为当前页面. 示例: // index.jsPage({ onShow( ...
- Vue在移动端App中使用的问题总结
1.客户端中弹出键盘使得fixed布局错乱 Vue 在移动端中使用,当弹出键盘时,fixed 布局的元素可能会被键盘顶起. 例子图示及解决方法参考:https://blog.csdn.net/qq_3 ...
- 获取第几个class
假如类名为a,如果是同级(兄弟元素)的,如:<ul><li class='a'></li><li class='a'></li></u ...
- 嵌入式逻辑分析仪SignalTap II 设计范例
Crazy Bingo :嵌入式逻辑分析仪SignalTap II 设计范例 例程下载地址 http://www.cnblogs.com/crazybingo/archive/2011/07/26/ ...
- Anaconda-navigator 打不开的解决方法(亲测有效!)
本文链接:https://blog.csdn.net/qq_42489092/article/details/92208822method_1:每当你打不开应用时,不妨试一下:用管理员身份运行 请用管 ...
- Educational Codeforces Round 16 E. Generate a String (DP)
Generate a String 题目链接: http://codeforces.com/contest/710/problem/E Description zscoder wants to gen ...