hdu-6437-最大费用流
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
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
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
1990
#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-最大费用流的更多相关文章
- 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 ...
- Coding Contest HDU - 5988(费用流)
题意: 有n个区域和m条路,每个区域有a[i]个人和b[i]个食物,然后是m条路连接两个区域,这条路容量为cap,这条路断掉的概率为p,第一个经过的时候一定不会断,后面的人有概率p会断,现在需要所有人 ...
- HDU 4862 Jump 费用流
又是一个看了题解以后还坑了一天的题…… 结果最后发现是抄代码的时候少写了一个负号. 题意: 有一个n*m的网格,其中每个格子上都有0~9的数字.现在你可以玩K次游戏. 一次游戏是这样定义的: 你可以选 ...
- hdu 6437 /// 最小费用最大流 负花费 SPFA模板
题目大意: 给定n,m,K,W 表示n个小时 m场电影(分为类型A.B) K个人 若某个人连续看了两场相同类型的电影则失去W 电影时间不能重叠 接下来给定m场电影的 s t w op 表示电影的 开始 ...
- HDU 4862(费用流)
Problem Jump (HDU4862) 题目大意 给定一个n*m的矩形(n,m≤10),每个矩形中有一个0~9的数字. 一共可以进行k次游戏,每次游戏可以任意选取一个没有经过的格子为起点,并且跳 ...
- hdu 4322 最大费用流
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4322 #include <cstdio> #include <cstring> ...
- HDU 6437 Problem L.Videos (最大费用)【费用流】
<题目链接> 题目大意: 一天有N个小时,有m个节目(每种节目都有类型),有k个人,连续看相同类型的节目会扣w快乐值.每一种节目有都一个播放区间[l,r].每个人同一时间只能看一个节目,看 ...
- HDU 6437 最(大) 小费用最大流
Problem L.Videos Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Other ...
- Going Home HDU - 1533 费用流
http://acm.hdu.edu.cn/showproblem.php?pid=1533 给一个网格图,每两个点之间的匹配花费为其曼哈顿距离,问给每个的"$m$"匹配到一个&q ...
- Tour HDU - 3488 有向环最小权值覆盖 费用流
http://acm.hdu.edu.cn/showproblem.php?pid=3488 给一个无源汇的,带有边权的有向图 让你找出一个最小的哈密顿回路 可以用KM算法写,但是费用流也行 思路 1 ...
随机推荐
- [exceltolist] - 一个excel转list的工具
https://github.com/deadzq/cp-utils-excelreader <(感谢知名网友的帮助) https://sargeraswang.com/blog/2018/1 ...
- windows service in vs
用 vs2013 创建 windows service 程序 vs2015开发Windows服务 VS 2010一步步开发windows服务(windows service)
- Jenkins-Publish HTML reports
创建job:testreport 在job中添加: 在Jenkins服务器上: 创建目录: .jenkins/jobs/{job名称}/workspace/htmlreports 注:此处job ...
- HDU 5754 Life Winner Bo(各类博弈大杂合)
http://acm.hdu.edu.cn/showproblem.php?pid=5754 题意: 给一个国际象棋的棋盘,起点为(1,1),终点为(n,m),现在每个棋子只能往右下方走,并且有4种不 ...
- 把一个List拆分为几个大小一样的List
static void Main(string[] args) { List<String> tarArr = new List<String>(); tarArr.Add(& ...
- 【Python】【jupyter-notebook】
1. win7 安装:https://www.cnblogs.com/zlslch/p/6984403.html 1.Jupyter Notebook 和 pip 为了更加方便地写 Python ...
- isnull和sum的关系
这是我刚刚写存储过程的时候意识到的一个问题!!! 先问大家这样一个问题,print 100+null 等于多少? 在一组数据统计的过程中,只要使用到sum函数,就必须使用isnull函数包含起来,因 ...
- 网页常见单位: px em pt % rem vw、vh、vmin、vmax , rem 使用
1.网页常见单位: px em pt vw\vh rem 1.1 px单位名称为像素,相对长度单位,像素(px)是相对于显示器屏幕分辨率而言 (最终解析单位) em单位名称为相对长度 ...
- Python数据分析-Day2-Pandas模块
1.pandas简介 Python Data Analysis Library 或 pandas 是基于NumPy 的一种工具,该工具是为了解决数据分析任务而创建的.Pandas 纳入了大量库和一些标 ...
- PHP添加Memcached扩展
1.下载memcached扩展 https://pecl.php.net/package/memcache 2.tar -xzvf memcache-2.2.7.tgz #解压memcached ...