【DP POJ 1821】Fence
来源:互联网 发布:淘宝优优管家是真的吗 编辑:程序博客网 时间:2024/05/22 06:20
Description
A team of k (1 <= K <= 100) workers should paint a fence which contains N (1 <= N <= 16 000) planks numbered from 1 to N from left to right. Each worker i (1 <= i <= K) should sit in front of the plank Si and he may paint only a compact interval (this means that the planks from the interval should be consecutive). This interval should contain the Si plank. Also a worker should not paint more than Li planks and for each painted plank he should receive Pi $ (1 <= Pi <= 10 000). A plank should be painted by no more than one worker. All the numbers Si should be distinct.
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
The input contains:
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
The output contains a single integer, the total maximal income.
Sample Input
8 43 2 23 2 33 3 51 1 7
Sample Output
17
I think
单调队列优化DP
Code
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int sm = 16000 + 5;int N,K;int q[sm],qv[sm],dp[110][sm];struct fence { int s,l,p;}f[sm];bool cmp(fence x,fence y) { return x.s<y.s;}int main() { scanf("%d%d",&N,&K); for(int i=1;i<=K;++i) scanf("%d%d%d",&f[i].l,&f[i].p,&f[i].s); sort(f+1,f+K+1,cmp); for(int i=1;i<=K;++i) { int now,s=1,t=1; for(int j=max(0,f[i].s-f[i].l);j<f[i].s;++j) { now=dp[i-1][j]-j*f[i].p; while(s<t&&now>q[t-1])--t; q[t]=now;qv[t++]=j; } for(int j=1;j<=N;++j) { dp[i][j]=max(dp[i-1][j],dp[i][j-1]); if(j<f[i].s||f[i].s+f[i].l-1<j)continue; while(s<t&&j-qv[s]>f[i].l)++s; dp[i][j]=max(dp[i][j],q[s]+j*f[i].p); } } printf("%d\n",dp[K][N]); return 0;}
- 【DP POJ 1821】Fence
- POJ 1821 Fence 单调队列优化DP
- poj 1821 Fence(dp+单调队列优化)
- POJ 1821 Fence 【DP动态规划】
- poj 1821 Fence(dp单调队列优化)
- poj 1821 Fence(单调队列+dp)
- POJ 1821 Fence 单调队列优化dp
- poj 1821 Fence(dp+单调队列优化)
- POJ 1821 Fence(DP+单调队列优化)
- POJ-1821 Fence(单调队列优化DP)
- poj 1821 Fence
- POJ 1821 Fence
- POJ 1821 - Fence
- poj 1821 Fence
- POJ 1821 Fence
- POJ 1821 Fence 笔记
- dp+计数 poj-1037-A decorative fence
- POJ 1037 A decorative fence(dp)
- 【Lucene&&Solr】Lucene索引和搜索流程
- 业界 | 摩根大通报告12个亮点总结:金融领域的机器学习工具有哪些?
- 解决Android Studio编译时出现GC overhead limit exceeded
- ArcEngine 10.1到10.2之间的相互编译问题--待解救
- 听说兼职网(http://www.freelives.cn)-源码解析
- 【DP POJ 1821】Fence
- java web 乱码问题
- USCAO-Section 1.3 Mixing Milk
- C++ namespace详解
- JSP页面结构
- 用CSS进行美化的新闻列表
- ELM原理
- kubernetes scheduler 启动过程及调度过程
- IIC设备驱动程序