POJ 1180 Batch Scheduling
来源:互联网 发布:翻译视频的软件 编辑:程序博客网 时间:2024/05/17 07:01
斜率优化DP
题意:给你N个jobs,要你去用一台或多台机器 顺序 完成,然后每一台机器启动之前需要S的时间去准备;
如果一台机器要完成3个jobs,那么这3个jobs完成的时间就都是 tt =(开始的时间 + S + t[a] + t[b] + t[c]);
所以代价是tt*f[a] + tt * f[b] + tt * f[c];
求完成所有jobs的最少代价
这一到题目的难点就是不知道最优解会用几台机器,前面用了多少台机器会影响后面的状态
所以我们可以试着倒推;
dp[i] 表示完成 i -- n 的jobs所需要的代价;
然后会有
st[i]表示t[i]+t[i+1]+...+t[n];
sf[i]表示f[i]+f[i+1]+...+f[n];
dp[i] = dp[k] + (s + st[i] - st[k]) * (sf[i] - sf[k]) + (s + st[i] - st[k]) * sf[k]; i<k<=n;
= dp[k] + (s + st[i] - st[k]) * sf[i] ;
接下来就是普通的斜率优化DP了;
#include <iostream>#include <cstring>#include <algorithm>#include <cstdio>using namespace std;const int INF = 1 << 30;const int N = 10005;int st[N], sf[N], q[N], t[N], f[N];int dp[N];int n,s;int getdp(int i, int k){ return dp[k] + (s + st[i] - st[k]) * sf[i];}int getup(int j, int k){ return dp[j] - dp[k];}int getdown(int j, int k){ return st[j] - st[k];}int main(){ int head, tail; while(~scanf("%d%d",&n,&s)){ memset(dp,0,sizeof(dp)); for(int i = 1; i <= n; i++){ scanf("%d%d", t+i, f+i); } st[n+1] = sf[n+1] = 0; for(int i = n; i > 0; i--){ st[i] = st[i+1] + t[i]; sf[i] = sf[i+1] + f[i]; } head = tail = 0; q[tail++] = n+1; for(int i = n; i > 0; i--){ while(head < tail-1 && getup(q[head+1], q[head]) <= sf[i] * getdown(q[head+1], q[head])) head++; dp[i] = getdp(i,q[head]); while(head < tail-1 && getup(q[tail-2], q[tail-1]) * getdown(q[tail-1], i) >= getup(q[tail-1], i) * getdown(q[tail-2], q[tail-1])) tail--; q[tail++] = i; } printf("%d\n",dp[1]); } return 0;}
0 0
- poj 1180 Batch Scheduling
- poj 1180 Batch Scheduling
- poj 1180 Batch Scheduling
- POJ 1180 Batch Scheduling
- poj 1180 Batch Scheduling 斜率优化dp
- poj 1180 Batch Scheduling ( 斜率优化DP )
- poj 1180 Batch Scheduling 斜率优化dp
- POJ 1180 Batch Scheduling (斜率优化DP)
- POJ - 1180 Batch Scheduling(斜率优化DP)
- POJ 1180 Batch Scheduling 已翻译
- poj 1180 Batch Scheduling dp斜率优化
- poj 1180 Batch Scheduling(DP-单调性优化)
- poj 1180 Batch Scheduling(斜率优化dp或决策单调)
- POJ-1180 Batch Scheduling 【逆向DP+斜率优化】
- Batch Scheduling
- PKU1180 Batch Scheduling
- 【动态规划】Batch Scheduling
- poj1180 Batch Scheduling
- wxpython comboBox 自动完成提示功能
- CSS层叠样式温故第一天
- Leet Code Medium 2 add two numbers
- PE格式详细讲解9– 导出表
- 置换元素(替换元素)和非置换元素(不可替换元素)
- POJ 1180 Batch Scheduling
- CSS3:简易的循环弹跳动画
- Linux命令备忘实例(8)——文件校验、分割与临时文件
- C++尽量不要使用#define
- 手机浏览器直接跳转打开微信方法
- 程序员怎样写好技术博客
- 怎样写rspec mailer测试
- 程序员中"5%神话";刘未鹏:为什么你应该写博客
- 欧几里得&扩展