博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 2479 (DP)
阅读量:4699 次
发布时间:2019-06-09

本文共 1049 字,大约阅读时间需要 3 分钟。

求一个区间内连续两段不相交区间最大和。

// File Name: 2479.cpp// Author: Missa_Chen// Created Time: 2013年06月22日 星期六 16时19分02秒#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;#define LL long longconst int inf = 0x3f3f3f3f;const int maxn = 5e4 + 5;int n;int num[maxn], st[maxn], end[maxn];int main(){ int cas; scanf("%d", &cas); while (cas --) { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &num[i]); for (int i = 0; i <= n + 1; ++i) st[i] = end[i] = -inf; int tmp = -inf, ans = -inf; for (int i = 1; i <= n; ++i) { if (tmp >= 0) tmp += num[i]; else tmp = num[i]; end[i] = max(end[i - 1], tmp); } tmp = -inf; for (int i = n; i >= 1; --i) { if (tmp >= 0) tmp += num[i]; else tmp = num[i]; st[i] = max(st[i + 1], tmp); } for (int i = 1; i < n; ++i) ans = max(ans, end[i] + st[i + 1]); printf("%d\n", ans); } return 0;}

  

转载于:https://www.cnblogs.com/Missa/p/3149888.html

你可能感兴趣的文章
12/17面试题
查看>>
LeetCode 242. Valid Anagram
查看>>
JSP表单提交乱码
查看>>
如何适应现代雇佣关系
查看>>
团队项目(第五周)
查看>>
SQL 优化经验总结34条
查看>>
开源 视频会议 收藏
查看>>
核心J2EE模式 - 截取过滤器
查看>>
.net开源CMS
查看>>
JdbcTemplate
查看>>
第一次使用maven记录
查看>>
SharePoint服务器端对象模型 之 使用CAML进展数据查询
查看>>
Building Tablet PC Applications ROB JARRETT
查看>>
Adobe® Reader®.插件开发
查看>>
【POJ 3461】Oulipo
查看>>
Alpha 冲刺 (5/10)
查看>>
使用Siege进行WEB压力测试
查看>>
斑马为什么有条纹?
查看>>
android多层树形结构列表学习笔记
查看>>
Android_去掉EditText控件周围橙色高亮区域
查看>>