Problem L.Videos

Problem Description:
C-bacteria takes charge of two kinds of videos: ’The Collection of Silly Games’ and ’The Collection of Horrible Games’.
For simplicity’s sake, they will be called as videoA and videoB.
There are some people who want to watch videos during today, and they will be happy after watching videos of C-bacteria.
There are n hours a day, m videos are going to be show, and the number of people is K.
Every video has a type(videoA or videoB), a running time, and the degree of happi- ness after someone watching whole of it.
People
can watch videos continuous(If one video is running on 2pm to 3pm and
another is 3pm to 5pm, people can watch both of them).
But each video only allows one person for watching.
For a single person, it’s better to watch two kinds to videos alternately, or he will lose W happiness.
For
example, if the order of video is ’videoA, videoB, videoA, videoB, …’
or ’B, A, B, A, B, …’, he won’t lose happiness; But if the order of
video is ’A, B, B, B, A, B, A, A’, he will lose 3W happiness.
Now you have to help people to maximization the sum of the degree of happiness.
 
Input
Multiple query.
On the first line, there is a positive integer T, which describe the number of data. Next there are T groups of data.
for
each group, the first line have four positive integers n, m, K, W : n
hours a day, m videos, K people, lose W happiness when watching same
videos).
and then, the next m line will describe m videos, four
positive integers each line S, T, w, op : video is the begin at S and
end at T, the happiness that people can get is w, and op describe it’s
tpye(op=0 for videoA and op=1 for videoB).
There is a blank line before each groups of data.
T<=20, n<=200, m<=200, K<=200, W<=20, 1<=S<T<=n, W<=w<=1000,
op=0 or op=1
 
Output
Your output should include T lines, for each line, output the maximum happiness for the corresponding datum.
 
Sample Input

Sample Output
 

题目大意:一天有N个小时,有m个节目(每种节目都有类型),有k个人,连续看相同类型的节目会扣w快乐值

每一种节目有都一个播放区间[l,r]。每个人同一时间只能看一个节目,看完可以获得快乐值。问最多可以获得多少快乐?

以下是根据样例一建立的图

建立源点、次源点、汇点。

将每个区间视为一个点,连续经过相同类型的点需要减去w的快乐值。

 #include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std; ///费用流
struct MCMF
{
static const int MAXN = ;
static const int MAXM = ;
static const int INF = 0x7FFFFFFF;
static const int INF0X3F = 0x3f3f3f3f;
int n, m, first[MAXN], s, t, sign;
int dist[MAXN], inq[MAXN], pre[MAXN], incf[MAXN];
int max_flow, min_cost; struct Edge
{
int to, cap, cost, next;
} edge[MAXM * ]; void init(int l, int r, int ss, int tt)
{
//for(int i = l; i <= r; i++ ){first[i] = -1;}
memset(first, -, sizeof(first));
s = ss, t = tt, sign = ;
max_flow = min_cost = ;
} void add_edge(int u, int v, int cap, int cost)
{
edge[sign].to = v, edge[sign].cap = cap, edge[sign].cost = cost;
edge[sign].next = first[u], first[u] = sign++;
edge[sign].to = u, edge[sign].cap = , edge[sign].cost = -cost;
edge[sign].next = first[v], first[v] = sign++;
} bool spfa(int s, int t)
{
for(int i = ; i < MAXN; i++ )
{
dist[i] = INF, inq[i] = ;
}
queue<int>que;
que.push(s), inq[s] = , dist[s] = ;
incf[s] = INF0X3F;
while(!que.empty())
{
int now = que.front();
que.pop();
inq[now] = ;
for(int i = first[now]; ~i; i = edge[i].next)
{
int to = edge[i].to, cap = edge[i].cap, cost = edge[i].cost;
if(cap > && dist[to] > dist[now] + cost)
{
dist[to] = dist[now] + cost;
incf[to] = min(incf[now], cap);
pre[to] = i;
if(!inq[to])
{
que.push(to);
inq[to] = ;
}
}
}
}
return dist[t] != INF;
}
void update(int s, int t)
{
int x = t;
while(x != s)
{
int pos = pre[x];
edge[pos].cap -= incf[t];
edge[pos ^ ].cap += incf[t];
x = edge[pos ^ ].to;
}
max_flow += incf[t];
min_cost += dist[t] * incf[t];
}
void minCostMaxFlow(int s, int t)
{
while(spfa(s, t))
{
update(s, t);
}
}
} p; const int MAXM = + ;
struct Node
{
int l, r, w, tp;
} arr[MAXM]; void solve()
{
/// 0 源点
/// m+m+1 次源点
/// m+m+2 汇点
int n, m, K, W;
scanf("%d %d %d %d", &n, &m, &K, &W);
p.init(, m+m+ , , m+m+); ///初始化 l,r,开始点,结束点 /*
* 建图
*/
p.add_edge(, m+m+, K, );
for(int i = ; i <= m; i++ )
scanf("%d%d%d%d", &arr[i].l, &arr[i].r, &arr[i].w, &arr[i].tp);
for(int i = ; i <= m; i++ )
{
for(int j = ; j <= m; j++ )
{
if(i == j)continue;
if(arr[i].r <= arr[j].l)
{
p.add_edge(i + m, j, , (arr[i].tp == arr[j].tp ? W : )); ///i+m为i拆出来的点
}
}
}
for(int i = ; i <= m; i++ )
{
p.add_edge(i, i + m, , -arr[i].w);
}
for(int i = ; i <= m; i++ )
{
p.add_edge(m+m+, i, , );
}
for(int i = ; i <= m; i++ )
{
p.add_edge(i + m, m+m+, , );
}
p.minCostMaxFlow(, m+m+);
printf("%d\n", -p.min_cost);
}; int main()
{
int T;
scanf("%d", &T);
while(T--)
{
solve();
}
return ;
}

hdu6437 Problem L.Videos(网络流)的更多相关文章

  1. [hdu6437]Problem L. Videos

    题目大意:有$n$个小时,有$m$个节目(每种节目都有类型$0/1$),有$k$个人,一个人连续看相同类型的节目会扣$w$快乐值. 每一种节目有都一个播放区间$[l,r]$.每个人同一时间只能看一个节 ...

  2. HDU 6437 Problem L.Videos (最大费用)【费用流】

    <题目链接> 题目大意: 一天有N个小时,有m个节目(每种节目都有类型),有k个人,连续看相同类型的节目会扣w快乐值.每一种节目有都一个播放区间[l,r].每个人同一时间只能看一个节目,看 ...

  3. HDU - 6437 Problem L.Videos 2018 Multi-University Training Contest 10 (最小费用最大流)

    题意:M个影片,其属性有开始时间S,结束时间T,类型op和权值val.有K个人,每个人可以看若干个时间不相交的影片,其获得的收益是这个影片的权值val,但如果观看的影片相邻为相同的属性,那么收益要减少 ...

  4. The Ninth Hunan Collegiate Programming Contest (2013) Problem L

    Problem L Last Blood In many programming contests, special prizes are given to teams who solved a pa ...

  5. Problem L

    Problem Description 在2×n的一个长方形方格中,用一个1× 2的骨牌铺满方格,输入n ,输出铺放方案的总数. 例如n=3时,为2× 3方格,骨牌的铺放方案有三种,如下图: L&qu ...

  6. Gym 102056L - Eventual … Journey - [分类讨论][The 2018 ICPC Asia-East Continent Final Problem L]

    题目链接:https://codeforces.com/gym/102056/problem/L LCR is really an incredible being. Thinking so, sit ...

  7. 2013-2014 ACM-ICPC, NEERC, Southern Subregional Contest Problem L. Stock Trading Robot 水题

    Problem L. Stock Trading Robot 题目连接: http://www.codeforces.com/gym/100253 Description CyberTrader is ...

  8. XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem L. Canonical duel

    题目:Problem L. Canonical duelInput file: standard inputOutput file: standard outputTime limit: 2 seco ...

  9. 2018 Multi-University Training Contest 4 Problem L. Graph Theory Homework 【YY】

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6343 Problem L. Graph Theory Homework Time Limit: 2000 ...

随机推荐

  1. javaweb入门-----request与response的作用

    request对象和request对象的原理 1.request和response对象request对象和request对象的原理时由服务器创建的,我们来使用它们 2.request对象是来获取请求消 ...

  2. 小伙子,你真的清楚 JVM GC ?

    序 正文 如何确定垃圾? 前面已经提到 JVM 可以采用 引用计数法 与 可达性分析算法 来确定需要回收的垃圾,我们来具体看一下这两种算法: 引用计数法 该方法实现为:给每个对象添加一个引用计数器,每 ...

  3. 放出一批jsp图书管理系统图书借阅系统源码代码运行

    基于jsp+mysql的JSP图书销售管理系统 https://www.icodedock.com/article/105.html基于jsp+Spring+Spring MVC的Spring图书借阅 ...

  4. 算法与数据结构基础 - 链表(Linked List)

    链表基础 链表(Linked List)相比数组(Array),物理存储上非连续.不支持O(1)时间按索引存取:但链表也有其优点,灵活的内存管理.允许在链表任意位置上插入和删除节点.单向链表结构一般如 ...

  5. 佳木斯集训Day6

    T1还是个找规律啊,记下b的个数,然后直接*2%10000000009就好了 #include <bits/stdc++.h> #define mo 1000000007 using na ...

  6. MongoDB之数据库备份与恢复

    MongoDB之数据备份与恢复 一,需求 一段时间备份数据库数据,以防意外导致数据丢失 二,备份与恢复 2.1,数据库备份 1,常用命令格式 mongodump -h IP --port 端口 -u ...

  7. javascript 异步请求封装成同步请求

    此方法是异步请求封装成同步请求,加上token验证,环境试用微信小程序,可以修改文件中的ajax,进行封装自己的,比如用axios等 成功码采用标准的 200 到 300 和304 ,需要可以自行修改 ...

  8. java根据经纬度查询门店地理位置-完美解决附近门店问题

    1.首先我们需要创建一个门店表如下: CREATE TABLE `app_store` ( `store_id` ) NOT NULL AUTO_INCREMENT COMMENT '发布id', ` ...

  9. python开发基础--思维导图

    开始学习python,相当于零基础 非自学,自学的痛苦不想体会和尝试,毕竟不会很友好,知乎上看到很多说自学的好处啊噼里啪啦的.嗯,说的很对,但是我偏不听,略略略.锻炼我的自学能力,这还需要锻炼吗,百度 ...

  10. vue 辅助开发工具(利用node自动生成相关文件,自动注册路由)

    vue 辅助开发工具 前言 有没有因为新建view,component,store的繁琐操作而苦恼,需要新建文件件,新建vue文件,新建js文件,注册路由...等一系列无价值操作浪费时间,为了解决这个 ...