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. Java 11 究竟比 8 快了多少?看看这个基准测试

    开源规划调度引擎 OptaPlanner 官网发布了一个 Java 11 GC 性能基准测试报告. 当前使用量最大的 Java 版本是 8,所以测试者用 Java 8 与 Java 11 进行对比测试 ...

  2. Oracle 基础学习笔记

    知识点 一.登陆数据库: 登陆数据库: sqlplus system/oracle123456 二.新建用户.授权(连接数据库.创建表.表空间.查询某用户下的表) 语法: create user [用 ...

  3. 剥开比原看代码11:比原是如何通过接口/create-account创建帐户的

    作者:freewind 比原项目仓库: Github地址:https://github.com/Bytom/bytom Gitee地址:https://gitee.com/BytomBlockchai ...

  4. Transaction之EF

    了解Entity Framework中事务处理 Entity Framework 6以前,框架本身并没有提供显式的事务处理方案,在EF6中提供了事务处理的API. 所有版本的EF,只要你调用SaveC ...

  5. Kubernetes之Controllers二

      Deployments A Deployment controller provides declarative updates for Pods and ReplicaSets. You des ...

  6. 通用程序返回结果类 ApplicationResult.cs

    using System.Collections.Generic; using System.Linq; namespace System { /// <summary> /// 表示应用 ...

  7. Codeforces 510 E. Fox And Dinner

    题目链接:http://codeforces.com/problemset/problem/510/E 乍一看和那啥魔术球问题有点神似啊/XD 其实是不一样的. 解决这道问题的关键在于发现若是相邻的两 ...

  8. codeforces 767C - Garland

    题目链接:http://codeforces.com/contest/767/problem/C 问能否将一棵带点权的书分成点权$3$块,求任意方案. 其实考虑一棵以$x$为根的子树权值为${\fra ...

  9. uiautomatorviewer错误 unable toconnect to adb

    报错信息: 如图为adb所在路径: 编辑uiautomatorviewer.bat文件,修改最后一行, 修改前: call "%java_exe%" "-Djava.ex ...

  10. Spring Bean的生命周期例子

    以下例子源于:W3Cschool,在此作记录 HelloWorld.java package com.how2java.w3cschool.beanlife; public class HelloWo ...