Problem L.Videos

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 492    Accepted Submission(s): 239

Problem Description
C-bacteria takes charge of two kinds of videos: ’The Collection of Silly Games’ and ’The Collection of Horrible Games’.
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.
 
Input
Multiple query.
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
 
Output
Your output should include T lines, for each line, output the maximum happiness for the corresponding datum.
 
Sample Input
2
10 3 1 10
1 5 1000 0
5 10 1000 1
3 9 10 0
10 3 1 10
1 5 1000 0
5 10 1000 0
3 9 10 0
 
Sample Output
2000
1990
 
Source
    
    首先要知道,求最大费用的话,可以将费用取相反数然后求最小费用,前提是没有负环。
    把每个电影看作是一个结点,由于每个电影只能被看一次,所以将一个节点分作两个中间连一条<cap=1,cost=0>的边,建立源点
S和S‘,S向S’建立一条<K,0>的边表示最多K个人,S‘向每个电影连<1,-w[i]>表示第一部观看的影片,建立汇点T,将所有电影点向T连接一条
<1,0>的边,然后电影之间根据条件建边,在满足t[i]<=s[j]的情况下,如果op相同,从i的结束点向j的出发点建立一条<1,-w[j]>的边,否则
<1,-(w[j]-W)>.
    然后跑最小费用流就好了。
    

 #include<bits/stdc++.h>
using namespace std;
#define LL long long
#define mp make_pair
#define pb push_back
#define inf 0x3f3f3f3f
#define pii pair<int,int> int first[],d[],a[],p[],tot,W,N,S,T,K,M;
bool vis[];
struct Edge{
int u,v,w,cap,flow,next;
}e[];
void add(int u,int v,int w,int cap){
e[tot]=Edge{u,v,w,cap,,first[u]};
first[u]=tot++;
e[tot]=Edge{v,u,-w,,,first[v]};
first[v]=tot++;
}
int spfa(int &flow,int &cost){
memset(d,inf,sizeof(d));
memset(vis,,sizeof(vis));
queue<int>q;
d[S]=,vis[S]=,a[S]=inf,p[S]=-;
q.push(S);
while(!q.empty()){
int u=q.front();
q.pop();
vis[u]=;
for(int i=first[u];~i;i=e[i].next){
if(e[i].cap>e[i].flow && d[e[i].v]>d[u]+e[i].w){
d[e[i].v]=d[u]+e[i].w;
p[e[i].v]=i;
a[e[i].v]=min(a[u],e[i].cap-e[i].flow);
if(!vis[e[i].v]){
q.push(e[i].v);
vis[e[i].v]=;
}
}
}
}
if(d[T]==inf) return ;
flow+=a[T];
cost+=d[T]*a[T];
int u=T;
while(u!=S){
e[p[u]].flow+=a[T];
e[p[u]^].flow-=a[T];
u=e[p[u]].u;
}
return ;
}
int solve(){
int flow=,cost=;
while(flow<K&&spfa(flow,cost));
return -cost;
}
int s[],t[],w[],op[];
int main()
{
int cas,i,j;
scanf("%d",&cas);
while(cas--){
tot=;
memset(first,-,sizeof(first));
scanf("%d%d%d%d",&N,&M,&K,&W);
for(i=;i<=M;++i){
scanf("%d%d%d%d",s+i,t+i,w+i,op+i);
add(i,i+M,,);
}
add(M*+,M*+,,K);
for(i=;i<=M;++i) {
add(M*+,i,-w[i],);
add(i+M,M*+,,);
}
for(i=;i<=M;++i){
for(j=;j<=M;++j){
if(i==j)continue;
if(s[j]>=t[i]){
if(op[i]==op[j]){
add(i+M,j,-(w[j]-W),);
}
else{
add(i+M,j,-w[j],);
}
}
}
}
S=M*+,T=M*+;
cout<<solve()<<endl;
}
return ;
}

hdu-6437-最大费用流的更多相关文章

  1. Mining Station on the Sea HDU - 2448(费用流 || 最短路 && hc)

    Mining Station on the Sea Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Jav ...

  2. Coding Contest HDU - 5988(费用流)

    题意: 有n个区域和m条路,每个区域有a[i]个人和b[i]个食物,然后是m条路连接两个区域,这条路容量为cap,这条路断掉的概率为p,第一个经过的时候一定不会断,后面的人有概率p会断,现在需要所有人 ...

  3. HDU 4862 Jump 费用流

    又是一个看了题解以后还坑了一天的题…… 结果最后发现是抄代码的时候少写了一个负号. 题意: 有一个n*m的网格,其中每个格子上都有0~9的数字.现在你可以玩K次游戏. 一次游戏是这样定义的: 你可以选 ...

  4. hdu 6437 /// 最小费用最大流 负花费 SPFA模板

    题目大意: 给定n,m,K,W 表示n个小时 m场电影(分为类型A.B) K个人 若某个人连续看了两场相同类型的电影则失去W 电影时间不能重叠 接下来给定m场电影的 s t w op 表示电影的 开始 ...

  5. HDU 4862(费用流)

    Problem Jump (HDU4862) 题目大意 给定一个n*m的矩形(n,m≤10),每个矩形中有一个0~9的数字. 一共可以进行k次游戏,每次游戏可以任意选取一个没有经过的格子为起点,并且跳 ...

  6. hdu 4322 最大费用流

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4322 #include <cstdio> #include <cstring> ...

  7. HDU 6437 Problem L.Videos (最大费用)【费用流】

    <题目链接> 题目大意: 一天有N个小时,有m个节目(每种节目都有类型),有k个人,连续看相同类型的节目会扣w快乐值.每一种节目有都一个播放区间[l,r].每个人同一时间只能看一个节目,看 ...

  8. HDU 6437 最(大) 小费用最大流

    Problem L.Videos Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Other ...

  9. Going Home HDU - 1533 费用流

    http://acm.hdu.edu.cn/showproblem.php?pid=1533 给一个网格图,每两个点之间的匹配花费为其曼哈顿距离,问给每个的"$m$"匹配到一个&q ...

  10. Tour HDU - 3488 有向环最小权值覆盖 费用流

    http://acm.hdu.edu.cn/showproblem.php?pid=3488 给一个无源汇的,带有边权的有向图 让你找出一个最小的哈密顿回路 可以用KM算法写,但是费用流也行 思路 1 ...

随机推荐

  1. 【Hadoop 分布式部署 八:分布式协作框架Zookeeper架构功能讲解 及本地模式安装部署和命令使用 】

    What  is  Zookeeper 是一个开源的分布式的,为分布式应用提供协作服务的Apache项目 提供一个简单的原语集合,以便与分布式应用可以在他之上构建更高层次的同步服务 设计非常简单易于编 ...

  2. Chrome上的扩展工具

    rest client - rest api Testing:类似fiddler的工具,可以测试url,查看返回值……

  3. 51nod1057-N的阶乘(大数乘法巧解)

    这道大数乘法开始我是想套板子模拟的..然后就发现2/3的例子都wa了.(惊了).然后在思考后发现n2的板子的确过不了这么多的大数.(不看题的下场).所以,我在网上发现了分块求大数的方法.%%% 思路来 ...

  4. C#中引用第三方ocx控件引发的问题以及解决办法

    调用OCX控件的步骤:1.在系统中注册该ocx控件,命令:regsvr32.exe 控件位置(加 /u 参数是取消注册)2.在.net的工具箱中添加该控件,拖到form中去就可以了. 不用工具箱的话, ...

  5. rostopic demo

    发布者 #!/usr/bin/env python2. # -*- coding: utf- -*- import rospy from hdw_driver.msg import update_fi ...

  6. win10 下载安装eclipse

    官网:https://www.eclipse.org 选择下载包 选择下载win 64版本 解压后目录结构如下: 点击运行eclipse

  7. 四: 使用vue搭建网站前端页面

    ---恢复内容开始--- 在搭建路由项目的时候的基本步骤 一:创建项目 安装好vue 搭好环境 (步骤在上篇博客中) 进入项目目录      cd   目录路径/ 目录名 创建项目          ...

  8. 关于git提示“warning: LF will be replaced by CRLF”终极解答

    一.发现问题 windows平台下使用git add,git deploy 文件时经常出现“warning: LF will be replaced by CRLF” 的提示. 网上很多解决办法提到: ...

  9. 《剑指offer》第六十四题(求1+2+…+n)

    // 面试题64:求1+2+…+n // 题目:求1+2+…+n,要求不能使用乘除法.for.while.if.else.switch.case // 等关键字及条件判断语句(A?B:C). #inc ...

  10. 人脸识别demo使用教程

    最近在研究虹软家的arcface 人脸识别 demo,现在就给大家分享一下官方的demo**工程如何使用? **1.下载代码:git clone https://github.com/asdfqwra ...