hdu6437 Videos 费用流
题目大意:
给出n,每天有n个小时。有m种电影,每个电影有开始时间和结束时间,和01两种种类,k个人,每一部电影只能被一个人看,会获得一个快乐值wi,如果一个人连续看两部相同种类的电影,快乐值会消耗W,(先加上wi,再减去W)。如果两部电影的开始时间和结束时间是重合的,则可以连续看。题目保证所有的wi都大于等于W。
思路:
拆点,将每一部电影拆成 i 和 i+m 两个点,建立一条费用为 -wi,流量为1的边,如果两部电影可以连着看,则建边,同种类的费用为W,不同种类的费用为0,建立一个源点连向所有电影,一个汇点也连接所有电影,一个超级源点,流量为k,连着源点。然后跑最小费用最大流,答案取负就可以了。
为什么这样就可以呢,因为题目保证了所有wi都大于W,也就是说,一部电影带来的收益肯定是正的,如果这个收益取负,那么我们就要最小的收益,而尽可能多的人就可以看尽可能多的电影,所以流量就要尽量大,这样就满足费用流的性质,然后就是建边稍微注意下,模板套一套就可以了。
#include<bits/stdc++.h>
#define CLR(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const int maxn=;
struct edge{
int v,f,w,Next;
edge(){}
edge(int a,int b,int c,int d){v = a,f=b,w=c,Next=d;}
}e[maxn*maxn];
int pree[maxn*],prevv[maxn*];
struct node{
int beg,en,val,op;
}video[maxn];
int tot=,head[maxn*],src,sink,dist[maxn*];
bool inque[maxn*];
inline void addv(int u,int v,int c,int w){
e[++tot]={v,c,w,head[u]};
head[u]=tot;
e[++tot]={u,,-w,head[v]};
head[v]=tot;;
}
inline void init(){
CLR(pree,);
CLR(prevv,);
tot=,CLR(head,);
}
int n,m,k,W;
inline bool findpath(){
queue<int >q;
q.push(src);
//printf("src:%d\n",src);
CLR(dist,inf);
CLR(inque,);
dist[src]=;
inque[src]=;
while(!q.empty())
{
int u=q.front();
q.pop();
inque[u]=;
for(int i=head[u]; i ;i=e[i].Next)
{
if(e[i].f > && dist[u]+e[i].w < dist[e[i].v]){
dist[e[i].v]=dist[u]+e[i].w;
prevv[e[i].v]=u;
pree[e[i].v]=i;
if(!inque[e[i].v]){
inque[e[i].v]=;
q.push(e[i].v);
}
} }
// printf("%d\n",u);
}
if(dist[sink]<inf)return true;
return false;
}
inline int augment(){
int u=sink;
int delta = inf ;
while(u!=src)
{
// printf("%d\n",u);
if(e[pree[u]].f<delta)delta = e[pree[u]].f;
u = prevv[u];
}
u= sink;
while(u!=src){
e[pree[u]].f -= delta;
e[pree[u] ^ ].f +=delta;
u = prevv[u];
}
return dist[sink]*delta;
} inline int mincostflow(){
int cur=,ans=;
while(findpath()){ cur += augment();
if(cur<ans)ans=cur;
}
return ans;
}
int main(){
int T;
cin>>T;
while(T--)
{
init(); scanf("%d%d%d%d",&n,&m,&k,&W);
src=*m+,sink=*m+;
for(int i=;i<=m;i++)
{
scanf("%d%d%d%d",&video[i].beg,&video[i].en,&video[i].val,&video[i].op);
}
for(int i=;i<=m;i++){
addv(i,i+m,,-video[i].val);
addv(src,i,,);
addv(i+m,sink,,);
for(int j=;j<=m;j++)
{
if(i==j)continue;
if(video[i].en<=video[j].beg){
if(video[i].op!=video[j].op)
{
addv(i+m,j,,);
}
else
{
addv(i+m,j,,W);
} }
}
}
src++;
addv(src,src-,k,);
printf("%d\n",-mincostflow()); }
}
Problem L.Videos
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 957 Accepted Submission(s): 474
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
hdu6437 Videos 费用流的更多相关文章
- HDU 6437 Problem L.Videos (最大费用)【费用流】
<题目链接> 题目大意: 一天有N个小时,有m个节目(每种节目都有类型),有k个人,连续看相同类型的节目会扣w快乐值.每一种节目有都一个播放区间[l,r].每个人同一时间只能看一个节目,看 ...
- HDU-6437 Videos
HDU-6437 题意:一天有n个小时,现在有m场电影,每场电影有一个愉悦值,有k个人,电影分2种类型A, B, 并且每一场电影只能一个人看, 一个人可以看无数次电影, 只要时间足够, 但是连续看同一 ...
- hdu-5988 Coding Contest(费用流)
题目链接: Coding Contest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Ot ...
- POJ2195 Going Home[费用流|二分图最大权匹配]
Going Home Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22088 Accepted: 11155 Desc ...
- BZOJ3130: [Sdoi2013]费用流[最大流 实数二分]
3130: [Sdoi2013]费用流 Time Limit: 10 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 960 Solved: 5 ...
- 洛谷 1004 dp或最大费用流
思路: dp方法: 设dp[i][j][k][l]为两条没有交叉的路径分别走到(i,j)和(k,l)处最大价值. 则转移方程为 dp[i][j][k][l]=max(dp[i-1][j][k-1][l ...
- Codeforces 730I [费用流]
/* 不要低头,不要放弃,不要气馁,不要慌张 题意: 给两行n个数,要求从第一行选取a个数,第二行选取b个数使得这些数加起来和最大. 限制条件是第一行选取了某个数的条件下,第二行不能选取对应位置的数. ...
- zkw费用流+当前弧优化
zkw费用流+当前弧优化 var o,v:..] of boolean; f,s,d,dis:..] of longint; next,p,c,w:..] of longint; i,j,k,l,y, ...
- 【BZOJ-4213】贪吃蛇 有上下界的费用流
4213: 贪吃蛇 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 58 Solved: 24[Submit][Status][Discuss] Desc ...
随机推荐
- Apache htcacheclean命令
一.简介 htcacheclean可以用于将mod_disk_cache的磁盘缓冲区占用的空间保持在一个合理的水平.这个工具可以手动运行也可以作为后台守护进程运行.当作为守护进程运行的时候,它将每隔一 ...
- openpyxl模块处理excel文件
python模块之——openpyxl 处理xlsx/ xlsm文件 项目原因需要编辑excel文件,经过查询,最先尝试xlwt .wlrd这个两个模块,但是很快发现这两个模块只能编辑xls文件,然而 ...
- 安全、结构良好的jQuery结构模板
安全.结构良好的jQuery结构模板 ;(function($,window,document,undefined){ //我们的代码- })(jQuery,window,document); 参 ...
- 设计模式06: Adapter 适配器模式(结构型模式)
Adapter 适配器模式(结构型模式) 适配(转换)的概念无处不在:电源转接头.电源适配器.水管转接头... 动机(Motivation)在软件系统中,由于应用环境的变化,常常需要将“一些现存的对象 ...
- TypedValue.applyDimension的使用
TypedValue.applyDimension是一个将各种单位的值转换为像素的方法 用法TypedValue.applyDimension(int unit, float value,Displa ...
- Task 回调
前正无生意,且记录Task回调之用法. using System; using System.Collections.Generic; using System.Diagnostics; using ...
- dubbo 安装部署Windows
1 安装zookeeper 2 安装dubbo 1 下载源码 https://github.com/alibaba/dubbo 2 编译 mvn clean package install -D ...
- 1222: FJ的字符串 [水题]
1222: FJ的字符串 [水题] 时间限制: 1 Sec 内存限制: 128 MB 提交: 92 解决: 20 统计 题目描述 FJ在沙盘上写了这样一些字符串: A1 = “A” A2 = ...
- PHP的Composer 与 Packagist,简单入门
[转]http://www.php.cn/manual/view/34000.html Composer 是一个 杰出 的依赖管理器.在 composer.json 文件中列出你项目所需的依赖包,加上 ...
- oracle转义用单引号
参考:https://blog.csdn.net/learning_oracle_lh/article/details/46639507