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

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

题解:最大费用最大流,为了保证每个影片只被一个人观看,将其拆为入点和出点,入点和出点之间连一条容量为$1$,花费为$0$的边。

建一个源点$ST$和次源点$st$。从$ST$向$st$建一条容量为$k$,花费为$0$的边,表示有$k$个人可以看影片。

从$st$点向每个入点连一条容量为$1$,花费为$val_i$的边,若两个影片的时间不相交($T_u \leqslant S_v$),那么在$u$到$v$之间建一条容量为$1$,花费为$val_v$的边;若$u,v$属性相同则花费为$val_v-W$。

最后将每个出点向汇点连一条容量为$1$,花费为$0$的边。

卡点:1.不知道为啥数组开小(计算出来不会锅)

​   2.换电脑的时候代码未保存,把一份错误代码复制了过去(调了我一天)

C++ Code:

#include <cstdio>
#include <cstring>
#define maxn 1010
#define maxm 50100
const int inf = 0x3f3f3f3f;
int Tim;
int n, m, K, W, st, ed;
struct node {
int S, T, w, ty;
} s[maxn];
int q[maxn], h, t;
int d[maxn], pre[maxn];
bool vis[maxn];
int head[maxn], cnt = 2;
struct Edge {
int to, nxt, w, cost;
} e[maxm << 1];
void add(int a, int b, int c, int d) {
e[cnt] = (Edge) {b, head[a], c, d}; head[a] = cnt;
e[cnt ^ 1] = (Edge) {a, head[b], 0, -d}; head[b] = cnt ^ 1;
cnt += 2;
}
inline int min(int a, int b) {return a < b ? a : b;}
bool spfa() {
for (int i = st; i <= ed; i++) d[i] = -inf;
d[q[h = t = 0] = st] = 0;
while (h <= t) {
int u = q[h++];
vis[u] = false;
for (int i = head[u]; i; i = e[i].nxt) {
int v = e[i].to;
if (e[i].w && d[v] < d[u] + e[i].cost) {
d[v] = d[u] + e[i].cost;
pre[v] = i;
if (!vis[v]) {
q[++t] = v;
vis[v] = true;
}
}
}
}
return d[ed] != -inf;
}
int update() {
int ans, mf = inf;
for (int i = pre[ed]; i; i = pre[e[i ^ 1].to]) mf = min(mf, e[i].w);
ans = mf * d[ed];
for (int i = pre[ed]; i; i = pre[e[i ^ 1].to]) e[i].w -= mf, e[i ^ 1].w += mf;
return ans;
}
void MCMF() {
int ans = 0;
while (spfa()) ans += update();
printf("%d\n", ans);
}
int main() {
scanf("%d", &Tim);
while (Tim --> 0) {
scanf("%d%d%d%d", &n, &m, &K, &W);
st = 0; ed = m + 1 << 1;
add(st, 1, K, 0);
for (int i = 1; i <= m; i++) {
scanf("%d%d%d%d", &s[i].S, &s[i].T, &s[i].w, &s[i].ty);
add(i << 1, i << 1 | 1, 1, 0);
add(1, i << 1, 1, s[i].w);
add(i << 1 | 1, ed, 1, 0);
}
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= m; j++) {
if (i != j && s[i].T <= s[j].S) add(i << 1 | 1, j << 1, 1, (s[i].ty == s[j].ty) ? s[j].w : s[j].w - W);
}
}
MCMF();
if (Tim) memset(head, 0, sizeof head), cnt = 2;
}
return 0;
}

  

[hdu6437]Problem L. Videos的更多相关文章

  1. hdu6437 Problem L.Videos(网络流)

    Problem L.Videos Problem Description: C-bacteria takes charge of two kinds of videos: ’The Collectio ...

  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. Hibernate无法提取结果集

    原因:表结构错误或 与 映射文件不一致 org.springframework.dao.InvalidDataAccessResourceUsageException: could not extra ...

  2. docker-compose 构建mongodb并导入基础数据示例

    使用docker-compose构建mongodb服务并导入基础数据示例. 1.文件目录结构 ——mongo/ |——docker-compose.yml |——mongo-Dockerfile |— ...

  3. Percona-Tookit工具包之pt-pmp

      Preface       Sometimes we need to know the details of a program(porcess) when it is running even ...

  4. angular常见问题总结

    本文引自:https://www.cnblogs.com/zhoulujun/p/8881414.html 这篇是对angularJS的一些疑点回顾,是对目前angularJS开发的各种常见问题的整理 ...

  5. git的使用入门

    写作目的: 快速的上手git版本控制+github神器进行基本的版本同步操作. 怎么做? 对于任意一个代码项目,使用git_bash进入到代码目录 如果没有进行过初始化操作:应当使用git init  ...

  6. perl实现监控linux

    1.使用root用户telnet进入linux系统 2.修改DNS以下两种方法 A.通过setup命令配置dns B.通过在/etc目录下创建resolv.conf文件 3.查看DNS是否配置成功 [ ...

  7. CSS3裁剪与遮罩解析

    一.用途 CSS3裁剪与遮罩(Clipping and Masking)用来隐藏元素的一部分而显示另一部分 二.区别 CSS3裁剪与遮罩(Clipping and Masking)用来隐藏元素的一部分 ...

  8. java 值传递 和 引用传递

    参考:(http://www.cnblogs.com/woshimrf/p/5263018.html) 参考:(http://www.cnblogs.com/binyue/p/3862276.html ...

  9. 《Cracking the Coding Interview》——第1章:数组和字符串——题目1

    2014-03-18 01:25 题目:给定一个字符串,判断其中是否有重复字母. 解法:对于可能有n种字符的字符集,用一个长度为n的数组统计每个字符的出现次数,大于1则表示有重复. 代码: // 1. ...

  10. [译]9-spring bean的生命周期

    spring中bean的生命周期比较容易理解.bean在实例化之后有时需要调用某个初始化方法进行一些初始化的工作.同样的 ,当bean在销毁之前有时需要做一些资源回收的工作. 尽管bean在实例化和销 ...