hdu6437 Problem L.Videos(网络流)
Problem L.Videos
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.
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
题目大意:一天有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(网络流)的更多相关文章
- [hdu6437]Problem L. Videos
题目大意:有$n$个小时,有$m$个节目(每种节目都有类型$0/1$),有$k$个人,一个人连续看相同类型的节目会扣$w$快乐值. 每一种节目有都一个播放区间$[l,r]$.每个人同一时间只能看一个节 ...
- HDU 6437 Problem L.Videos (最大费用)【费用流】
<题目链接> 题目大意: 一天有N个小时,有m个节目(每种节目都有类型),有k个人,连续看相同类型的节目会扣w快乐值.每一种节目有都一个播放区间[l,r].每个人同一时间只能看一个节目,看 ...
- HDU - 6437 Problem L.Videos 2018 Multi-University Training Contest 10 (最小费用最大流)
题意:M个影片,其属性有开始时间S,结束时间T,类型op和权值val.有K个人,每个人可以看若干个时间不相交的影片,其获得的收益是这个影片的权值val,但如果观看的影片相邻为相同的属性,那么收益要减少 ...
- 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 ...
- Problem L
Problem Description 在2×n的一个长方形方格中,用一个1× 2的骨牌铺满方格,输入n ,输出铺放方案的总数. 例如n=3时,为2× 3方格,骨牌的铺放方案有三种,如下图: L&qu ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- UE4 游戏模块初始化顺序
最近看教学,有个讲解UE4初始化顺序的,记录一下. 首先创建一个Actor,Character,GameInstance,GameMode,LevelScriptActor(关卡),PlayerCon ...
- JavaScript数据结构——集合的实现与应用
与数学中的集合概念类似,集合由一组无序的元素组成,且集合中的每个元素都是唯一存在的.可以回顾一下中学数学中集合的概念,我们这里所要定义的集合也具有空集(即集合的内容为空).交集.并集.差集.子集的特性 ...
- StarUML 3.0 破解方法
首先在我这里下载 StarUML3.0 破解替换文件app.asar 链接:https://pan.baidu.com/s/1wDMKDQkKrE9D1c0YeXz0xg 密码:y65m 然后参照下 ...
- 02.Mybatis的动态代理方式实现增删改查
动态代理的方式实现增删改查: 通过约定的方式定位sql语句 约定 > 配置文件 > 硬编码 约定的目标是省略掉通过硬编码的方式定位sql的代码,通过接口直接定位出sql语句,以下代码为通过 ...
- JAVA基础知识(五)数据类型转换
当使用 +.-.*./.%.运算操作时,遵循如下规则: 1.只要两个操作数中有一个是double类型的,另一个将会被转换成double类型,并且结果也是double类型: 2.如果两个操作数中有一个 ...
- 转载 | 一种让超大banner图片不拉伸、全屏宽、居中显示的方法
现在很多网站的Banner图片都是全屏宽度的,这样的网站看起来显得很大气.这种Banner一般都是做一张很大的图片,然后在不同分辨率下都是显示图片的中间部分.实现方法如下: <html> ...
- 5月29日 Java性能调优指南 读后感
并行垃圾收集器 串行垃圾收集器 并发标记清除(CMS)垃圾收集器 Garbage First(G1)垃圾收集器 没有深入的学习G1的原理,只是看了大概的思想; SA工具:待学习
- c语言ld returned 1 exit status😂
在复习c语言过程中遇到, 问题:reverseLinkedList.exe: Permission denied collect2.exe: error: ld returned 1 exit sta ...
- Prometheus 集成 Node Exporter
文章首发于公众号<程序员果果> 地址:https://mp.weixin.qq.com/s/40ULB9UWbXVA21MxqnjBxw 简介 Prometheus 官方和一些第三方,已经 ...
- EVE-NG入门篇
目录 一.EVE-NG配置要求 二.EVE-NG 安装 三.基于OVA的安装步骤 四.导入设备介绍 五.启动设备 六.与secure CRT关联 七.常见问题 一.EVE-NG配置要求 1.最低配置 ...