Fence
来源:互联网 发布:网络诚信会有什么风险 编辑:程序博客网 时间:2024/05/22 12:05
题目链接:http://poj.org/problem?id=1821
这道题首先是以动规,那么我的dp[i][j]设为前i个人刷了j块木板,最后一块是第j块,是第i个人刷完的最大收益,首先我们要将每个人规定刷完的木板进行排序,因为这个是有顺序刷的,状态转移方程就是:dp[i][j]=max(dp[i-1][j],dp[i-1][k]+[j-k]*p),第i个人没有刷,或者是刷了j-k块,那么第二个状态就会运用到单调队列的思想,求出k,就算最大值。具体可以看代码:
#include<iostream>#include<cstdio>#include<deque>#include<cstring>#include<algorithm>using namespace std;struct node{ int l,p,s; bool operator<(const node& w) const{ return s<w.s; }}num[110];const int inf=0x3f3f3f3f;struct news{ int val; int pos; news (int v,int p):val(v),pos(p){}};int dp[110][16000];int n,m;deque<news>q;int main(){ scanf("%d%d",&n, &m); for(int i = 1; i<= m; i++) { scanf("%d%d%d",&num[i].l, &num[i].p, &num[i].s); } sort(num+1, num+m+1); for(int i = 1;i<= m;i++) { for(int j = 1; j<= n; j++) dp[i][j] = dp[i-1][j]; q.clear(); for(int k = max(num[i].s-num[i].l,0); k< num[i].s; k++) { int value = dp[i-1][k] - k * num[i].p; while(!q.empty() && q.back().val < value) q.pop_back(); q.push_back(news(value,k)); } for(int j = num[i].s; j < num[i].s+num[i].l; j++) { while(!q.empty() && q.front().pos < j-num[i].l) q.pop_front(); dp[i][j] = max(dp[i][j], q.front().val + j*num[i].p); } } int maxn = -inf; for(int i = 1; i<= n; i++) { if(dp[m][i] > maxn) maxn = dp[m][i]; } printf("%d\n", maxn); return 0;}
0 0
- fence
- Fence
- Fence
- Fence
- Memory Fence
- Electric Fence
- poj1031 fence
- Memory Fence
- Electric Fence
- Fancy Fence
- Fence Repair
- Fence Repair
- Fence Repair
- Electric Fence
- Fence Loops
- Fence Rails
- B. Fence
- B. Fence
- Windows socket 通信
- Linux常用命令总结
- Bad version number in .class file这个问题的解决方法
- cmd运行java.class,错误:找不到或无法加载主类
- hdu_1513 Palindrome
- Fence
- Dame Parajumpers Jakke crime is a bad Pei son
- Atcoder 045
- jdbc学习总结二
- visual studio 2015 安装路径不能修改
- 【DP or 生成函数】[CodeForces - 712D]Memory and Scores
- java对时间的相关操作
- Android Camera(一) 调用系统相机应用
- java用户角色权限设计