POJ1337---A Lazy Worker(dp)

本文探讨了一位懒惰工人的工作安排问题,通过设定硬性截止日期来确保任务的有效执行。采用动态规划方法,实现了对工人总工作时间的最小化,并提供了完整的代码实现。

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.

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

3
3
15 0 25
50 0 90
45 15 70
3
15 5 20
15 25 40
15 45 60
5
3 3 6
3 6 10
3 14 19
6 7 16
4 4 11

Sample Output

50
45
15

Source
Taejon 2002

dp[i] 表示到时刻i时,最少的执行时间
然后暴力枚举可以转移到的工作
然而我们不需要担心如果选入某个工作j,是否存在之前转移过来的状态里已经有工作j,因为某个工作可以执行的时间<2*t ,所以不会被选入第二次

/*************************************************************************
    > File Name: POJ1337.cpp
    > Author: ALex
    > Mail: zchao1995@gmail.com 
    > Created Time: 2015年06月01日 星期一 21时50分17秒
 ************************************************************************/

#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <map>
#include <bitset>
#include <set>
#include <vector>

using namespace std;

const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const double eps = 1e-15;
typedef long long LL;
typedef pair <int, int> PLL;

int dp[330];
struct node {
    int ti, ai, di;
}Jobs[110];

int cmp(node a, node b) {
    return a.ai < b.ai;
}

int main() {
    int t;
    scanf("%d", &t);
    while (t--) {
        int n, LongTime = 0;
        int ti, ai, di;
        scanf("%d", &n);
        for (int i = 1; i <= n; ++i) {
            scanf("%d%d%d", &ti, &ai, &di);
            ++ai;
            ++di;
            Jobs[i].ti = ti;
            Jobs[i].ai = ai;
            Jobs[i].di = di;
            LongTime = max(LongTime, di);
        }
        sort(Jobs + 1, Jobs + 1 + n, cmp);
        memset(dp, inf, sizeof(dp));
        dp[0] = 0;
        for (int j = 0; j <= LongTime; ++j) {
            bool flag = 0;
            for (int i = 1; i <= n; ++i) {
                if (dp[j] == inf) {
                    continue;
                }
                if (j >= Jobs[i].ai && j + Jobs[i].ti <= Jobs[i].di) {
                    dp[j + Jobs[i].ti] = min(dp[j + Jobs[i].ti], dp[j] + Jobs[i].ti);
                    flag = 1;
                }
            }
            if (!flag) {
                dp[j + 1] = min(dp[j + 1], dp[j]);
            }
        }
        printf("%d\n", dp[LongTime]);
    }
    return 0;
}
内容概要:本文系统介绍了标准化和软件知识产权的基础知识,涵盖标准化的基本概念、分类、标准代号、国际标准的采用原则及程度,重点讲解了信息技术标准化、ISO与IEC等国际标准化组织以及ISO9000和ISO/IEC15504等重要标准体系;在知识产权部分,详细阐述了知识产权的定义、分类及特点,重点分析了计算机软件著作权的主体、客体、权利内容、行使方式、保护期限及侵权认定,同时涉及商业秘密的构成与侵权形式、专利权的类型与申请条件,以及企业如何综合运用著作权、专利、商标和商业秘密等方式保护软件知识产权。; 适合人群:从事软件开发、项目管理、IT标准化或知识产权相关工作的技术人员与管理人员,以及备考相关资格考试的学习者;具备一定信息技术背景,希望系统掌握标准化与软件知识产权基础知识的专业人员。; 使用场景及目标:①帮助理解各类标准的分类体系及国际标准采用方式,提升标准化实践能力;②指导企业在软件研发过程中有效保护知识产权,规避法律风险;③为软件著作权登记、专利申请、技术保密等提供理论依据和操作指引。; 阅读建议:建议结合国家相关政策法规和实际案例进行深入学习,重点关注软件著作权与专利权的适用边界、标准制定流程及企业知识产权管理策略,强化理论与实践的结合。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值