题目大意:有$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. Apache.Tomcat 调用Servlet原理之Class类的反射机制,用orc类解释

    有一个兽人类 package com.swift.servlet; public class OrcDemo { private int hp; private int mp; private int ...

  2. block简介

    ios4.0系统已开始支持block,在编程过程中,blocks被Obj-C看成是对象,它封装了一段代码,这段代码可以在任何时候执行.Blocks可以作为函数参数或者函数的返回值,而其本身又可以带输入 ...

  3. cocos2dx 修改亮度、对比度、色调、饱和度

    废话少说,直接修改CCSprite使用的片面着色器ccShader_PositionTextureColor_noMVP.frag: /* * cocos2d for iPhone: http://w ...

  4. 干货!一篇文章集合所有Linux基础命令,适合所有菜鸟学习和老手回顾!

    1 文件{ ls -rtl # 按时间倒叙列出所有目录和文件 ll -rt touch file # 创建空白文件 rm -rf 目录名 # 不提示删除非空目录(-r:递归删除 -f强制) dos2u ...

  5. 【shopex】真正可用的app开发机制

    shopex的app开发机制详解   网上流传的shopex4.8.5的app开发教程,不仅说得不明不白,而且由于版本问题,照着做根本是做不成的. 知其然,亦要知其所以然. shopex提供了的一个干 ...

  6. 【c学习-5】

    int main(){ //二维数组的应用 int i,j; int a[2][3]; for(i=0;i void myFunction(){ int a[3]; int i; int max; f ...

  7. Java源码解析——Java IO包

    一.基础知识: 1. Java IO一般包含两个部分:1)java.io包中阻塞型IO:2)java.nio包中的非阻塞型IO,通常称为New IO.这里只考虑到java.io包中堵塞型IO: 2. ...

  8. 【TP5.1】HTML标签自动转义,导致CKEditor保存内容无法正常显示!

    问题:使用Thinkphp5.1 开发的时候显示CKEditor保存的内容不符合预期. 希望的样子,肯定是不显示<p><b>等标签,而是下面的样子. 因为刚开始使用TP5.1和 ...

  9. 创建数据库配置文件ini(转)

    一.有必要了解INI文件的结构: ;注释 [小节名] 关键字=值 ... ---- INI文件允许有多个小节,每个小节又允许有多个关键字, “=”后面是该关键字的值. ---- 值的类型有三种:字符串 ...

  10. eBay 表结构

    erp_ebay_list 建表语句 CREATE TABLE `erp_ebay_list` ( `id` ) NOT NULL AUTO_INCREMENT COMMENT '自增主键', `na ...