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. Learning to Compare Image Patches via Convolutional Neural Networks --- Reading Summary

    Learning to Compare Image Patches via Convolutional Neural Networks ---  Reading Summary 2017.03.08 ...

  2. [HDU 1976] Software Version

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

  3. Global.asax.cs中相关方法

    protected void Session_Start(object sender, EventArgs e) { #if DEBUG //debug 登陆默认设置 #endif } protect ...

  4. docker 命令随笔

    如果是容器传输文件到本地的话,反过来就好了: docker cp  ID全称:容器文件路径   本地路径 2.进入docker 容器 docker exec -it fw-pay-trade-serv ...

  5. BZOJ 4808: 马(二分图最大点独立集)

    http://www.lydsy.com/JudgeOnline/problem.php?id=4808 题意: 思路: 这图中的两个马只能选一个,二选一,很像二分图吧,对能互吃的两个棋子连线,在所选 ...

  6. SQLServer代理新建或者编辑作业报错

    SQLServer代理新建或者编辑作业的时候报错如下 错误信息: 标题: Microsoft SQL Server Management Studio------------------------- ...

  7. JSONObject的parseArray方法作用。

    该方法将字符串数据转换成集合对象. String dep_tree = JedisUtils.getInstance().get(CacheConstant.DEP_TREE, user.getId( ...

  8. P2002 消息扩散

    其实这道题蛮水的 思路: 根据题意,他说有环,自然想到要用tarjan,后面就很简单了: 缩完点之后重新建图,开一个inin数组表示该点的入度是多少(psps:该点表示缩完点之后的大点): 最后统计一 ...

  9. android 利用CountDownTimer实现时分秒倒计时效果

    https://blog.csdn.net/mrzhao_perfectcode/article/details/81289578

  10. MySQL学习(十)

    要做:商城的留言板 一般情况,做留言板的显示很容易,直接select查询,再显示出来,但eschop中的留言板难点在于留言数据来自2张表,feedback表和comment表,我们需要把两张表中的内容 ...