POJ 1821 Fence
Fence
This problem will be judged on PKU. Original ID: 1821
64-bit integer IO format: %lld Java class name: Main
Being the team's leader you want to determine for each worker the interval that he should paint, knowing that the total income should be maximal. The total income represents the sum of the workers personal income.
Write a program that determines the total maximal income obtained by the K workers.
Input
Input
N K
L1 P1 S1
L2 P2 S2
...
LK PK SK
Semnification
N -the number of the planks; K ? the number of the workers
Li -the maximal number of planks that can be painted by worker i
Pi -the sum received by worker i for a painted plank
Si -the plank in front of which sits the worker i
Output
Sample Input
8 4
3 2 2
3 2 3
3 3 5
1 1 7
Sample Output
17
Hint
the worker 1 paints the interval [1, 2];
the worker 2 paints the interval [3, 4];
the worker 3 paints the interval [5, 7];
the worker 4 does not paint any plank
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = ;
struct Worker{
int L,S,P;
bool operator<(const Worker &rhs) const{
return S < rhs.S;
}
}a[maxn];
int n,m,L[maxn],R[maxn],dp[][maxn],q[maxn]; int main(){
while(~scanf("%d%d",&n,&m)){
for(int i = ; i <= m; ++i)
scanf("%d%d%d",&a[i].L,&a[i].P,&a[i].S);
sort(a + , a + m + );
for(int i = ; i <= m; ++i){
L[i] = max(,a[i].S - a[i].L);
R[i] = min(n,a[i].S + a[i].L - );
}
for(int i = ; i <= m; ++i){
for(int j = ; j <= R[i]; ++j)
dp[i][j] = dp[i-][j];
int hd = ,tl = ;
for(int j = L[i]; j < a[i].S; ++j){
while(hd < tl && dp[i-][j] - j*a[i].P >= dp[i-][q[tl-]] - q[tl-]*a[i].P) --tl;
q[tl++] = j;
}
for(int j = a[i].S; j <= R[i]; ++j){
while(hd < tl && j - q[hd] > a[i].L) ++hd;
dp[i][j] = max(dp[i-][j],dp[i][j-]);
dp[i][j] = max(dp[i][j],dp[i-][q[hd]] + (j - q[hd])*a[i].P);
}
for(int j = R[i] + ; j <= n; ++j)
dp[i][j] = max(dp[i-][j],dp[i][j-]);
}
int ret = ;
for(int i = ; i <= n; ++i)
ret = max(ret,dp[m][i]);
printf("%d\n",ret);
}
return ;
}
POJ 1821 Fence的更多相关文章
- poj 1821 Fence(单调队列优化DP)
poj 1821 Fence \(solution:\) 这道题因为每一个粉刷的人都有一块"必刷的木板",所以可以预见我们的最终方案里的粉刷匠一定是按其必刷的木板的顺序排列的.这就 ...
- poj 1821 Fence 单调队列优化dp
/* poj 1821 n*n*m 暴力*/ #include<iostream> #include<cstdio> #include<cstring> #incl ...
- poj 1821 Fence(单调队列)
题目链接:http://poj.org/problem?id=1821 题目分析来自:http://blog.csdn.net/tmeteorj/article/details/8684453 连续的 ...
- POJ 1821 Fence (算竞进阶习题)
单调队列优化dp 我们把状态定位F[i][j]表示前i个工人涂了前j块木板的最大报酬(中间可以有不涂的木板). 第i个工人不涂的话有两种情况: 那么F[i - 1][j], F[i][j - 1]就成 ...
- POJ 1821 Fence(单调队列优化DP)
题解 以前做过很多单调队列优化DP的题. 这个题有一点不同是对于有的状态可以转移,有的状态不能转移. 然后一堆边界和注意点.导致写起来就很难受. 然后状态也比较难定义. dp[i][j]代表前i个人涂 ...
- POJ 3253 Fence Repair(修篱笆)
POJ 3253 Fence Repair(修篱笆) Time Limit: 2000MS Memory Limit: 65536K [Description] [题目描述] Farmer Joh ...
- POJ 3253 Fence Repair (优先队列)
POJ 3253 Fence Repair (优先队列) Farmer John wants to repair a small length of the fence around the past ...
- poj 3253 Fence Repair 优先队列
poj 3253 Fence Repair 优先队列 Description Farmer John wants to repair a small length of the fence aroun ...
- POJ 3253 Fence Repair (贪心)
Fence Repair Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
随机推荐
- 使用GitHub(转载)
转自:http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/00137628548491 ...
- win10系统下,开启数据库远程连接方式
右键左下角的windows标志,选择控制面板 2.查看方式修改为大图标 3.选择高级设置 4.新建入站规则 5.选择端口然后下一步 6.选择tcp协议,端口输入80,3306 7.选择允许连接 8.规 ...
- J20170618-hm
番兵(ばんぺい) 哨兵 後始末 善后
- layout 自适应详解
@{ ViewBag.Title = "人员查找"; ViewBag.LeftWidth = "200px"; ViewBag.MiddleW ...
- Elasticsearch之CURL命令的bulk批量操作
大家,也可去看看我下面的博客 Elasticsearch之批量操作bulk 官网上,是举例了新建一个requests文件. [hadoop@master elasticsearch-]$ pwd /h ...
- 微信接口本地调试(IIS服务器)
1.下载ngrok,并注册获得token.官网下载地址:https://ngrok.com/ 如果你是在官网下载的,到后面映射域名的时候会要求购买他们的服务. 这里我们用一个国内免费的ngrok服务器 ...
- Jquery 实现列表的显示和隐藏
本人github源码下载地址:https://github.com/liuyanpeng521/ListChange.git
- OFDM同步算法之Minn算法
minn算法代码 算法原理 训练序列结构 T=[B B -B -B],其中B表示由长度为N/4的复伪随机序列PN,ifft变换得到的符号序列 (原文解释):B represent samples of ...
- 【转】Java 集合系列06之 Vector详细介绍(源码解析)和使用示例
概要 学完ArrayList和LinkedList之后,我们接着学习Vector.学习方式还是和之前一样,先对Vector有个整体认识,然后再学习它的源码:最后再通过实例来学会使用它.第1部分 Vec ...
- lnmp环境搭建后续-php安装
安装PHP7: 下载# wget http://PHP.net/get/php-7.0.2.tar.gz/from/a/mirror 建议安装之前先看看安装帮助文件INSTALL 解压安装 # tar ...