POJ 1337 A Lazy Worker(DP)
来源:互联网 发布:mysql frm hy000 编辑:程序博客网 时间:2024/06/07 08:47
Description
There is a worker who may lack the motivation to perform at his peak level of efficiency because he is lazy. He wants to minimize the amount of work he does (he is Lazy, but he is subject to a constraint that he must be busy when there is work that he can do.)
We consider a set of jobs 1, 2,..., n having processing times t1, t2,...,tn respectively. Job i arrives at time ai and has its deadline at time di. We assume that ti, ai, and di have nonnegative integral values. The jobs have hard deadlines, meaning that each job i can only be executed during its allowed interval Ii=[ai, di]. The jobs are executed by the worker, and the worker executes only one job at a time. Once a job is begun, it must be completed without interruptions. When a job is completed, another job must begin immediately, if one exists to be executed. Otherwise, the worker is idle and begins executing a job as soon as one arrives. You should note that for each job i, the length of Ii, di - ai, is greater than or equal to ti, but less than 2*ti.
Write a program that finds the minimized total amount of time executed by the worker.
We consider a set of jobs 1, 2,..., n having processing times t1, t2,...,tn respectively. Job i arrives at time ai and has its deadline at time di. We assume that ti, ai, and di have nonnegative integral values. The jobs have hard deadlines, meaning that each job i can only be executed during its allowed interval Ii=[ai, di]. The jobs are executed by the worker, and the worker executes only one job at a time. Once a job is begun, it must be completed without interruptions. When a job is completed, another job must begin immediately, if one exists to be executed. Otherwise, the worker is idle and begins executing a job as soon as one arrives. You should note that for each job i, the length of Ii, di - ai, is greater than or equal to ti, but less than 2*ti.
Write a program that finds the minimized total amount of time executed by the worker.
Input
The input consists of T test cases. The number of test cases (T ) is given in the first line of the input file. The number of jobs (0<=n<=100) is given in the first line of each test case, and the following n lines have each job's processing time(1<=ti<=20),arrival time(0<=ai<=250), and deadline time (1<=di<=250) as three integers.
Output
Print exactly one line for each test case. The output should contain the total amount of time spent working by the worker.
Sample Input
3315 0 2550 0 9045 15 70315 5 2015 25 4015 45 6053 3 63 6 103 14 196 7 164 4 11
Sample Output
504515
简单DP,刷表即可。注意n==0,RE无数发。
设DP[i]为前i分钟最小工作时间。
#include<cstdio>#include<cstring>#include<algorithm>#include<vector>#include<string>#include<iostream>#include<queue>#include<cmath>#include<map>#include<stack>#include<bitset>using namespace std;#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )#define CLEAR( a , x ) memset ( a , x , sizeof a )typedef long long LL;typedef pair<int,int>pil;const int INF = 0x3f3f3f3f;int dp[550];struct node{ int st; int a,b;}e[110];int t,n,mi,mx;int main(){ scanf("%d",&t); while(t--) { scanf("%d",&n); mx=0;mi=0; REPF(i,1,n) { scanf("%d%d%d",&e[i].st,&e[i].a,&e[i].b); mx=max(mx,e[i].b); mi=min(mi,e[i].a); } CLEAR(dp,INF); dp[mi]=0; for(int i=mi;i<=mx;i++) { int flag=1; for(int j=1;j<=n;j++) { if(i>=e[j].a&&i<=e[j].b&&i+e[j].st<=e[j].b) { dp[i+e[j].st]=min(dp[i+e[j].st],dp[i]+e[j].st); flag=0; } } if(flag) dp[i+1]=min(dp[i+1],dp[i]); } printf("%d\n",dp[mx]); } return 0;}/**/
0 0
- A Lazy Worker - POJ 1337 dp
- POJ 1337 A Lazy Worker(DP)
- poj 1337 A Lazy Worker
- POJ 1337 A Lazy Worker
- POJ 1337 A Lazy Worker 笔记
- POJ1337---A Lazy Worker(dp)
- poj 2430 Lazy Cows 状压dp
- POJ 2430 Lazy Cows 状压DP
- Poj A Simple Problem with Integers(lazy线段树)
- poj 3468 A Simple Problem with Integers LAZY线段树
- poj 3468 A Simple Problem with Integers(线段树+lazy)
- POJ-3468-A Simple Problem with Integers(Lazy算法)
- poj 2295: A DP Problem
- A Worker Reads History
- poj 3468 lazy
- POJ 2430 Lazy Cows
- poj 2430 Lazy Cows
- poj 2430 Lazy Cows
- leetcode--19Remove Nth Node From End of List
- php学习随记4
- AES加密解密(使用php扩展mcrypt实现AES加密)
- oracle rac IO 隔离的存储SCSI锁原理
- 北大光华学院学生研究报告-关于超级表格创业
- POJ 1337 A Lazy Worker(DP)
- 3-6
- struts2学习笔记之十六(token标签)
- 单例设计模式 浅谈
- Oracle存储过程update受外键约束的主键值时完整性冲突解决方案
- HTML锚点&JSP锚点
- 第六章习题汇总
- Median of Two Sorted Arrays
- 浏览一天的收获