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 ...
随机推荐
- ubuntu下借助qt creator创建属于自己的共享库
简介: 在 Windows 上,共享库由 .dll 表示:在 Linux 上,由 .so 表示. Shared Library的优势 共享库,又称动态库或so文件,顾名思义,它可以在可执行文件启动时加 ...
- Model设计中常见的技巧和注意事项
verbose_name 可以作为第一个参数传入,书写更加工整和有序: name = models.CharField('类别名',default="", max_length=3 ...
- Permission 使用详解
极力推荐文章:欢迎收藏 Android 干货分享 阅读五分钟,每日十点,和您一起终身学习,这里是程序员Android 本篇文章主要介绍 Android 开发中的部分知识点,通过阅读本篇文章,您将收获以 ...
- jquery EasyUi 添加节点、展开所有节点、默认选中第一个节点
感觉easyUi 的树用起来不如 Ext 的树方便,首先,root节点不太好自定义, 异步加载时,只能通过后台判断生成root节点,但是这样一来有一个问题,就是第一次访问界面时, 树的初始化比较慢,大 ...
- 阿里P8Java大牛仅用46张图让你弄懂JVM的体系结构与GC调优。
本PPT从JVM体系结构概述.GC算法.Hotspot内存管理.Hotspot垃圾回收器.调优和监控工具六大方面进行讲述.图文并茂不生枯燥. 此PPT长达46页,全部展示篇幅过长,本文优先分享前十六页 ...
- CSS:抗锯齿 font-smoothing
本文引自:http://www.cnblogs.com/sunshq/p/4595673.html -webkit-font-smoothing 这个属性可以使页面上的字体抗锯齿,使用后字体看起来会更 ...
- Opengl_入门学习分享和记录_02_渲染管线(一)顶点着色器&片段着色器
写在前面的废话:今天俺又来了哈哈,真的好棒棒! 今天的内容:之前我们大概描述了,我们自己定义的顶点坐标是如何被加载到GPU之中,并且介绍了顶点缓冲对象VBO用于管理这一块内存.今天开始详细分析它的具体 ...
- java高并发系列 - 第24天:ThreadLocal、InheritableThreadLocal(通俗易懂)
java高并发系列第24篇文章. 环境:jdk1.8. 本文内容 需要解决的问题 介绍ThreadLocal 介绍InheritableThreadLocal 需要解决的问题 我们还是以解决问题的方式 ...
- python语言特点简介 以及在Windows以及Mac中安装以及配置的注意事项
正如前一篇随笔所提到的,python属于解释型语言 python语言有两个特点: 1.胶水语言(历史遗留问题,原来Perl语言作为Unix内置标准件,获得极大追捧,作为竞争者的python一开始是作为 ...
- Flutter学习笔记(18)--Drawer抽屉组件
如需转载,请注明出处:Flutter学习笔记(18)--Drawer抽屉组件 Drawer(抽屉组件)可以实现类似抽屉拉出和推入的效果,可以从侧边栏拉出导航面板.通常Drawer是和ListView组 ...