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. (转) AdversarialNetsPapers

      本文转自:https://github.com/zhangqianhui/AdversarialNetsPapers AdversarialNetsPapers The classical Pap ...

  2. 用RAR将多个文件夹一次性压缩为多个对应zip文件

    选中要压缩的所有文件夹.右键,选“添加到压缩文件...”,弹出的菜单如下图: 点击菜单栏“文件”.在“把每个文件都单独压缩文件中”选中,才可以单独创建压缩.如下图

  3. Latex: IEEEtrans模板下 扩大标题宽度

    参考: Extending side margins for Title section in IEEEtrans document class Latex: IEEEtrans模板下 扩大标题宽度 ...

  4. 【译】第10节---数据注解-Key

    原文:http://www.entityframeworktutorial.net/code-first/key-dataannotations-attribute-in-code-first.asp ...

  5. super()、this属性与static静态方法的执行逻辑

    1.super的构造顺序:永远优先构造父类的方法 2.static永远在类实例之前执行,this的使用范围为实例之后

  6. 蚂蚁金服首席数据科学家漆远:AI技术开放,与业界融合共创

    小蚂蚁说: 11月8日,在第五届世界互联网大会-<人工智能:融合发展新机遇>论坛上,蚂蚁金服副总裁.首席数据科学家漆远认为AI具有控制风险.降本增效和提升用户体验三大作用. 11月8日,第 ...

  7. 牛客小白月赛7 CSL的校园卡

    CSL的校园卡 思路: bfs,用状压表示走过的区域,然后和x1,y1,x2,y2构成所有的状态,然后标记一下就可以了 代码: #pragma GCC optimize(2) #pragma GCC ...

  8. JAVA中Action层, Service层 ,modle层 和 Dao层的功能区分

    Dao层是使用了Hibernate连接数据库.操作数据库(增删改查).Service层:引用对应的Dao数据库操作,在这里可以编写自己需要的代码(比如简单的判断).Action层:引用对应的Servi ...

  9. Anaconda 简单介绍 -- 环境管理

    前面介绍了 Anaconda 的安装,接下来介绍一下 简单使用,后续并实时更新. 常用操作命令: 环境操作 1.查看环境管理的全部命令帮助: conda env -h 2.查看当前系统下的环境: co ...

  10. java重新开始学习

    1.从菜鸟网站开始学习.http://www.runoob.com/java/java-tutorial.html 2. String args[] 与 String[] args 还有一个就是Str ...