POJ 3245|Sequence Partitioning|动态规划|单调队列
来源:互联网 发布:星云数据服务平台 编辑:程序博客网 时间:2024/05/17 06:42
题意真是难懂。。
题意
一个长度为
题解
二分答案。
能否破除
考虑什么情况下必须捆绑在一起。
如果
所以考虑排序
然后剩下的就没有限制了,于是问题就变成,给出一个数列,(每个组a的最大值)的和不能超过limit,(各组内b的的和)的最大值最小。
那么和POJ 3017很类似了?
一个单调队列优化DP
不过POJ 3017必须要set维护,本题就无所谓了。。
代码
#include <cstdio>#include <algorithm>using namespace std;const int N = 50005, inf = 0x7fffffff;int n, limit, q[N], a[N], b[N], dp[N], p1[N], p2[N];bool check(int m) { int i, j = 1, k, s = 0, f = 0, r = 0; for (i = 1; i <= n; ++i) { s += b[i]; while (s > m) s -= b[j++]; if (j > i) return 0; while (f < r && a[q[r - 1]] <= a[i]) --r; while (f < r && q[f] < j) ++f; q[r++] = i; dp[i] = dp[j - 1] + a[q[f]]; for (k = f + 1; k < r; ++k) dp[i] = min(dp[i], dp[q[k - 1]] + a[q[k]]); } return dp[n] <= limit;}bool cmp(int x, int y) { return b[x] < b[y];}int main() { int i, j, l, r, mid; while (scanf("%d%d", &n, &limit) == 2) { for (i = 1; i <= n; ++i) scanf("%d%d", &a[i], &b[i]), p1[i] = p2[i] = i; sort(p1 + 1, p1 + n + 1, cmp); for (j = 1, i = n; i >= 1; --i) for (; j <= n && b[p1[j]] <= a[i]; ++j) p2[p1[j]] = i; for (i = 1, j = 1; i <= n; i = l, ++j) { a[j] = a[i]; b[j] = b[i]; for (l = i + 1, r = max(p2[i], i); l <= r; ++l) { a[j] = max(a[j], a[l]); b[j] += b[l]; r = max(r, p2[l]); } } n = j - 1; for (l = 0, r = inf; l < r) { mid = l + r >> 1; if (check(mid)) r = mid; else l = mid + 1; } printf("%d\n", l); } return 0;}
Sequence Partitioning
Time Limit: 8000MS Memory Limit: 65536K
Total Submissions: 1286 Accepted: 346
Case Time Limit: 5000MS
Description
Given a sequence of
For any two pairs
Let
it is provided that
where Limit is a given integer.
Let
Could you tell me the minimum?
Input
The input contains exactly one test case. The first line of input contains two positive integers
Output
Output the minimum target value.
Sample Input
4 64 33 52 52 4
Sample Output
9
Hint
An available assignment is the first two pairs are assigned into the first part and the last two pairs are assigned into the second part. Then
Source
POJ Monthly–2007.07.08, Chen, Danqi
- POJ 3245|Sequence Partitioning|动态规划|单调队列
- poj 3245 Sequence Partitioning(dp+二分+单调队列+sbt)
- poj 3245 Sequence Partitioning dp+二分+单调队列
- poj 3245 Sequence Partitioning dp+二分+单调队列
- POJ 3017|Cut the Sequence|动态规划|单调队列
- [POJ 3245] Sequence Partitioning [动态规划+线段树]
- [POJ3245] Sequence Partitioning && dp单调队列+二分
- poj 3245 Sequence Partitioning
- POJ 3017 单调队列+最值优化 的动态规划
- [POJ 3926][Vjudge 19611] Parade [动态规划+单调队列]
- 单调队列优化动态规划
- 动态规划之单调队列
- 单调队列优化动态规划
- POJ 3017 Cut the Sequence 单调队列
- Cut the Sequence,Sequence Partitioning,POJ3017,POJ3245,用单调队列优化的DP
- 【动态规划\单调队列】逃亡的准备
- 关于动态规划的单调队列优化
- bzoj1855 股票交易 动态规划&单调队列
- java代码优化(长期更新)
- tomcat 启动not found for the web module
- startx 启动的过程
- C++第四次实验——输出星号图
- 2016 微软编程之美复赛题目中文翻译
- POJ 3245|Sequence Partitioning|动态规划|单调队列
- CALayer详解
- 字符串的indexof(),substring()和split()的方法
- POJ 1493 Machined Surfaces
- 喝酒
- 集成融云Android SDK实现在群聊/讨论组中@人的功能(二)
- 约瑟夫环扩展问题
- C#开发蓝牙服务端,自动配对以及收发消息
- atlas(keepalived)+mysql(MHA)