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 ...
随机推荐
- JS-数组的定义
- C# 委托(delegate)、泛型委托和Lambda表达式
目录 # 什么是委托 # 委托声明.实例化和调用 1.声明 2.委托的实例化 3.委托实例的调用 4.委托完整的简单示例 #泛型委托 1.Func委托 2.Action委托 3.Predicate委托 ...
- codeforces 339 D.Xenia and Bit Operations(线段树)
这个题目属于线段树的点更新区间查询,而且查的是整个区间,其实不用写query()函数,只需要输出根节点保存的值就可以了. 题意: 输入n,m表示有2^n个数和m个更新,每次更新只把p位置的值改成b,然 ...
- TensorFlow学习笔记——深层神经网络的整理
维基百科对深度学习的精确定义为“一类通过多层非线性变换对高复杂性数据建模算法的合集”.因为深层神经网络是实现“多层非线性变换”最常用的一种方法,所以在实际中可以认为深度学习就是深度神经网络的代名词.从 ...
- 用html和css写一个头部header和左侧菜单栏menu-bar固定的的页面
这个页面header部分是100%的宽度,60px的高度,左侧是刚好一屏的高度,180的宽度,右侧的部分把剩余的空间占满,刚开始的时候还没怎么接触这样的页面,以为使用js读取浏览的可视化宽高,然后在做 ...
- 【精选】Markdown 语法汇总
博客园也能Markdown?美滋滋,Markdown真的是好用QAQ. 本文档按照Markdown各种常用语法类别,以文字描述+演示的方式来展现markdown语法的使用.Markdown 的目标是实 ...
- SpringBoot配置web访问H2
[**前情提要**]最近开始搭建博客,在本地调试的时候使用的数据库是h2,但是调试的时候需要查看数据库,本文也由此而来. --- 下面是我用到的方法: 1. 使用IDEA的Database连接工具,具 ...
- java并发编程(十九)----(JUC集合)总体框架介绍
本节我们将继续学习JUC包中的集合类,我们知道jdk中本身自带了一套非线程安全的集合类,我们先温习一下java集合包里面的集合类,然后系统的看一下JUC包里面的集合类到底有什么不同. java集合类 ...
- warpAffine仿射变换
仿射变换,其实就是不同的坐标系的相互转换,用于图像的平移和旋转. 首先看一下官方的api描述. https://docs.opencv.org/2.4/modules/imgproc/doc/geom ...
- net core Webapi基础工程搭建(四)——日志功能log4net
目录 前言 log4net 依然是,NuGet引用第三方类库 整合LogUtil 小结 前言 一个完整的项目工程离不开日志文件的记录,而记录文件的方法也有很多,可以自己通过Stream去实现文件的读写 ...