poj 2593 Max Sequence(线性dp)
题目链接:http://poj.org/problem?id=2593
思路分析:该问题为求给定由N个整数组成的序列,要求确定序列A的2个不相交子段,使这m个子段的最大连续子段和的和最大。
该问题与poj 2479相同,解法也一样;
代码如下:
#include <cstdio>
#include <iostream>
using namespace std; const int MAX_N = + ;
int arr[MAX_N], dp_s[MAX_N], dp_r[MAX_N];
int arr_num; int main(int argc, char *argv[])
{
int temp_ans, sum, ans; while (scanf("%d", &arr_num) != EOF && arr_num != )
{
for (int i = ; i < arr_num; ++i)
scanf("%d", &arr[i]); temp_ans = INT_MIN, sum = ;
for (int i = ; i < arr_num; ++i)
{
if (sum >= )
sum += arr[i];
else
sum = arr[i];
if (sum > temp_ans)
temp_ans = sum;
dp_s[i] = temp_ans;
} temp_ans = INT_MIN, sum = ;
for (int i = arr_num - ; i >= ; --i)
{
if (sum >= )
sum += arr[i];
else
sum = arr[i];
if (sum > temp_ans)
temp_ans = sum;
dp_r[i] = temp_ans;
} ans = dp_s[] + dp_r[];
for (int i = ; i < arr_num - ; ++i)
{
int sum = dp_s[i] + dp_r[i + ];
if (sum > ans)
ans = sum;
}
printf("%d\n", ans);
} return ;
}
poj 2593 Max Sequence(线性dp)的更多相关文章
- POJ 2479 Maximum sum POJ 2593 Max Sequence
d(A) = max{sum(a[s1]..a[t1]) + sum(a[s2]..a[t2]) | 1<=s1<=t1<s2<=t2<=n} 即求两个子序列和的和的最大 ...
- POJ 2593 Max Sequence
Max Sequence Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 17678 Accepted: 7401 Des ...
- POJ 1458-Common Subsequence(线性dp/LCS)
Common Subsequence Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 39009 Accepted: 15 ...
- poj 1141 Brackets Sequence (区间dp)
题目链接:http://poj.org/problem?id=1141 题解:求已知子串最短的括号完备的全序列 代码: #include<iostream> #include<cst ...
- poj 1836 Alignment(线性dp)
题目链接:http://poj.org/problem?id=1836 思路分析:假设数组为A[0, 1, …, n],求在数组中最少去掉几个数字,构成的新数组B[0, 1, …, m]满足条件B[0 ...
- poj 1141 Brackets Sequence 区间dp,分块记录
Brackets Sequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 35049 Accepted: 101 ...
- POJ 1141 Brackets Sequence(区间DP, DP打印路径)
Description We give the following inductive definition of a “regular brackets” sequence: the empty s ...
- poj 1141 Brackets Sequence ( 区间dp+输出方案 )
http://blog.csdn.net/cc_again/article/details/10169643 http://blog.csdn.net/lijiecsu/article/details ...
- HDOJ 1003 Max Sum(线性dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003 思路分析:该问题为最大连续子段和问题,使用动态规划求解: 1)最优子结构:假设数组为A[0, 1 ...
随机推荐
- c#Ulong用一个高位Uint和低位Uint表示
有时候考虑到平台之间的通用性,可能把一个Ulong拆分成2个Uint来进行各平台之间的通讯,当时转换的时候有点头晕,对与或预算不是很熟悉,不过还是花了半小时弄出来了,代码: //ulong的最大值2^ ...
- find: missing argument to `-exec'
man find 发现 花括号要加 '' find ${LOG_BASE_DIR}$dir/ -type f -mtime +${KEEP_DAYS} -name ${LOG_REG} -exec r ...
- C++学习之函数指针
C++学习之函数指针 和数据项类似,函数也有地址,函数的地址是存储在机器语言代码的内存的开始地址.通常,这些地址对用户而言,不重要也没什么用处,但对程序而言,它却很有用. 一.函数 ...
- WPF:向客户端发出某一属性值已更改的通知INotifyPropertyChanged接口
Person.cs using System.ComponentModel; namespace _01_INotifyPropertyChanged { class Person:INotifyPr ...
- (4)事件处理——(2)在页面加载的时候执行任务(Performing tasks on page load)
We have already seen how to make jQuery react to the loading of a web page. The $(document).ready()e ...
- C iOcp
#include <winsock2.h> //#include <windows.h> #include <stdio.h> #define PORT 5150 ...
- Android实现获取应用程序相关信息列表的方法
本文所述为Androdi获取手机应用列表的方法,比如获取到Android应用的软件属性.大小和应用程序路径.应用名称等,获取所有已安装的Android应用列表,包括那些卸载了的,但没有清除数据的应用程 ...
- cocos2dx 字体BMFont,Atlas
为了更加个性化,系统提供的字体,有时候没法满足我们的要求,所以cocos2dx提供了自定义字体控件. 分别是CCLabelBMFont和CCLabelAtlas,先看BMFont的效果 CCLabel ...
- CodeForces 22C System Administrator
把v和2结点交换, 1和v连,其它点和v之间能够互相连. #include <iostream> #include <cstdlib> #include <cstring ...
- /etc/ld.so.conf详解
/etc/ld.so.conf 此文件记录了编译时使用的动态库的路径,也就是加载so库的路径. 默认情况下,编译器只会使用/lib和/usr/lib这两个目录下的库文件,而通常通过源码包进行安装 ...