[dp]cf gym 101485B; bzoj4426 Better Productivity(NWERC 2015 B)

31 篇文章 0 订阅
12 篇文章 0 订阅

@(ACM题目)[dp]

Description

ACME Inc. is reorganizing their factory, in order to maximize their productivity of useless
trinkets. The new factory design consists of p independent and identical production lines. Each production line can be assigned some number of workers.
The actual work is of course all done by machines, so the production rate of a production line is independent of the actual number of workers assigned to it. However, the workers work in shifts, and due to local safety regulations, a production line can only be active while all of its workers are present (any worker who arrives before the last person to arrive, or leaves after the first person leaves, will be spending the inactive time having a coffee break). In other words, the productivity of a production line equals the length of the timespan during which all of the workers assigned to this production line are present. Crucially, the productivity of each line must be positive (i.e., the last worker to arrive for a line must arrive strictly before the first worker for that line leaves), since otherwise the workers feel that their jobs are meaningless.
Unfortunately, due to some pesky labor laws, ACME are not allowed to fire any of their workers,
which means that each of their n workers must be assigned to some production line, even though
this may actually decrease the overall productivity of the factory.
All these rules and regulations are making a headache for ACME management. Can you
help them figure out the maximum possible total productivity (sum of productivities of the p
production lines) of their new factory?

Input

The input consists of:
- one line containing two integers n and p (1 ≤ p ≤ n ≤ 200), the number of employees
and the number of production lines;
- n lines each containing two integers a and b (0 ≤ a < b ≤ 100 000), representing a
worker that arrives at time a and leaves at time b.
You may assume that there exists at least one valid assignment of workers to production lines.

Output

Output the maximum productivity level possible for the factory

Sample Input

4 2
1 3
1 5
4 6
2 7

Sample Output

4

分析

本题题意为n个区间分为p组,求每组交的和的最大值,每组的交不能为空。

将n个区间分为两个集合:

  • A集合中的区间能覆盖n个区间中的某一个
  • B集合中的区间不能覆盖n个区间中的任何一个
    若有多个相等区间,在B中留一个。

那么A中的若和其他的区间分为一组,不会起作用,故将A中的按贪心取最大的 k 个,每个一组,在B中分剩余pk组。

对于B,先将区间排序,dp[i][j]代表前i个区间,分为j组的最大值。只需考虑第i个区间与前面多少个分为一组,不断更新dp[i][j]即可。

#include <bits/stdc++.h>
using namespace std;
const int maxn = 200 + 5;
struct Data
{
    int l, r;
    bool operator < (const Data &rhs) const
    {
        if(l != rhs.l) return l < rhs.l;
        return r < rhs.r;
    }
}a[maxn], b[maxn];
int f[maxn][maxn]{0}, c[maxn];
int main()
{
    int n, p;
    cin >> n >> p;
    for(int i = 1; i <= n; ++ i)
        scanf("%d%d", &a[i].l, &a[i].r);
    sort(a + 1, a + n + 1);
    int cnt = 0, cnt2 = 0;
    for(int i = 1; i <= n; ++ i)
    {
        bool ck = true;
        for(int j = i + 1; j <= n; ++ j)
        {
            if(a[i].l <= a[j].l && a[i].r >= a[j].r)
            {
                ck = false;
                break;
            }
        }
        int k = i - 1;
        while(k >= 1 && a[k].l == a[i].l)
        {
            if(a[i].r > a[k].r)
            {
                ck = false;
                break;
            }
            --k;
        }
        if(ck) b[++cnt] = a[i];
        else c[++cnt2] = a[i].r - a[i].l;
    }
    f[1][1] = b[1].r - b[1].l;
    for(int i = 2; i <= cnt; ++ i)
    {
        for(int j = 1; j <= min(i, p); ++ j)
        {
            f[i][j] = 0;
            if(f[i-1][j-1]) f[i][j] = f[i-1][j-1] + b[i].r - b[i].l;
            for(int k = i - 1; k >= 1 && b[k].r > b[i].l; --k)
            {
                if(f[k-1][j-1] || k == 1)
                    f[i][j] = max(f[i][j], f[k-1][j-1] + b[k].r - b[i].l);
            }
        }
    }
    int res = f[cnt][p];
    int sum = 0;
    sort(c + 1, c + 1 + cnt2);
    for(int i = cnt2, j = 1; i >= 1 && j < p; ++ j , -- i)
    {
        sum += c[i];
        if(f[cnt][p - j])
            res = max(res, f[cnt][p-j] + sum);
    }
    cout << res << endl;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
动作捕获的3DMAX BIP库,共37个目录500个文件。 动作列表: 01 Sitting in chair and talking 坐在椅子上谈话(4 motions) 02 Sitting in chair and drinking 坐在椅子上饮水 (3 motions) 03 Sitting to standing 从座着到站立(7 motions) 04 Walk in, sit down 行走,坐下(23 motions) 05 Seated Conversations 坐着交谈(6 motions) 06 Walk and run cycles 走和跑圈(44 motions) 07 Transitions 转变-慢到快(4 motions) 08 Walking with Large Box 搬大箱子(4 motions) 09 Walking with limp 上坡(13 motions) 10 Walking with hands in pockets 提着袋子走路(21 motions) 11 Walking with cane 拄着拐杖行走(4 motions) 12 Walking with parasol 撑着阳伞(女)行走(10 motions) 13 Walks with umbrella 撑着雨伞行走(9 motions) 14 Character walks 行走特征(18 motions) 15 Character walks and runs 走和跑特征(34 motions) 16 Walk in, negotiate obstacle, walk out 行走,通过障碍(26 motions) 17 Carrying bags and weights 提着重物行走(49 motions) 18 Blind person 盲人(4 motions) 19 Drunken adults 醉酒-成人(9 motions) 20 Drunken teenagers 醉酒-孩子(8 motions) 21 Disabilities-Crutches 双手拐杖(22 motions) 22 Bunny Girl 可爱女郎(13 motions) 23 Walking and lying down 走路并躺下(6 motions) 24 Sweeping with broom 用扫帚清洗(11 motions) 25 Scrubbing Floor 擦地板(2 motions) 26 Various kneeling and bowing 各种跪和鞠躬(7 motions) 27 Ambient moves 四周移动(35 motions) 28 Picking Things Up 捡东西(9 motions) 29 Opening Doors 开门(16 motions) 30 Standing Conversations, Addresses 站着交谈(9 motions) 31 Office 办公室(3 motions) 32 Dancing 跳舞(6 motions) 33 Sport Moves 运动(15 motions) 34 Driving 驾驶(7 motions) 35 Manual Labor 手工劳动(17 motions) 36 Gym Characters 体育馆项目(12 motions) 37 Throwing and catching 抓和扔(10 motions)

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值