题目传送门

题目大意:

   给出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

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

hdu6437 Videos 费用流的更多相关文章

  1. HDU 6437 Problem L.Videos (最大费用)【费用流】

    <题目链接> 题目大意: 一天有N个小时,有m个节目(每种节目都有类型),有k个人,连续看相同类型的节目会扣w快乐值.每一种节目有都一个播放区间[l,r].每个人同一时间只能看一个节目,看 ...

  2. HDU-6437 Videos

    HDU-6437 题意:一天有n个小时,现在有m场电影,每场电影有一个愉悦值,有k个人,电影分2种类型A, B, 并且每一场电影只能一个人看, 一个人可以看无数次电影, 只要时间足够, 但是连续看同一 ...

  3. hdu-5988 Coding Contest(费用流)

    题目链接: Coding Contest Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Ot ...

  4. POJ2195 Going Home[费用流|二分图最大权匹配]

    Going Home Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22088   Accepted: 11155 Desc ...

  5. BZOJ3130: [Sdoi2013]费用流[最大流 实数二分]

    3130: [Sdoi2013]费用流 Time Limit: 10 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 960  Solved: 5 ...

  6. 洛谷 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 ...

  7. Codeforces 730I [费用流]

    /* 不要低头,不要放弃,不要气馁,不要慌张 题意: 给两行n个数,要求从第一行选取a个数,第二行选取b个数使得这些数加起来和最大. 限制条件是第一行选取了某个数的条件下,第二行不能选取对应位置的数. ...

  8. zkw费用流+当前弧优化

    zkw费用流+当前弧优化 var o,v:..] of boolean; f,s,d,dis:..] of longint; next,p,c,w:..] of longint; i,j,k,l,y, ...

  9. 【BZOJ-4213】贪吃蛇 有上下界的费用流

    4213: 贪吃蛇 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 58  Solved: 24[Submit][Status][Discuss] Desc ...

随机推荐

  1. 10.IN 操作符

    IN 操作符 IN 操作符允许我们在 WHERE 子句中规定多个值. SQL IN 语法 SELECT column_name(s) FROM table_name WHERE column_name ...

  2. Map集合的关联数组实现

    public class AssoiativeArray<K,V>{ //创建一个二维数组 private Object[][] pairs; //声明索引 private int ind ...

  3. 【原创】ListView快速滚动至新添加一行(自动滚动)

    在C#开发中我们经常要开发一些日志系统,尤其是基于ListView的日志显示系统.但是当日志增多是你是否有一些困扰,就是它为什么不会自动滚动至最后一行. 以下是一小段代码,希望可以帮助你. publi ...

  4. 黑盒测试实践-任务进度-Day03

    任务进度11-28 使用工具 selenium 小组成员 华同学.郭同学.穆同学.沈同学.覃同学.刘同学 任务进度 经过了前两天的学习任务的安排,以下是大家的任务进度: 华同学(任务1) 1.今天就接 ...

  5. python 字符串,元组, 列表,字典之间的转换

    #-*-coding:utf-8-*- #1.字典 dict = {'name': 'Zara', 'age': 7, 'class': 'First'} #字典转为字符串,返回:<type ' ...

  6. 编写高质量代码改善C#程序的157个建议——建议13: 为类型输出格式化字符串

    建议13: 为类型输出格式化字符串 有两种方法可以为类型提供格式化的字符串输出.一种是意识到类型会产生格式化字符串输出,于是让类型继承接口IFormattable.这对类型来 说,是一种主动实现的方式 ...

  7. LibreOJ 6278 数列分块入门 2(分块)

     题解:非常高妙的分块,每个块对应一个桶,桶内元素全部sort过,加值时,对于零散块O(sqrt(n))暴力修改,然后暴力重构桶.对于大块直接整块加.查询时对于非完整块O(sqrt(n))暴力遍历.对 ...

  8. .net Reflection(反射)- 一

    Reflection 反射需要引用 using System.Reflection; 命名空间.  通过 Assembly 类的 Load( ); 加载指定的 程序集 Assembly 是不能被实例化 ...

  9. Django-项目上线后,静态文件配置失效以及404、500页面的全局配置

    https://blog.csdn.net/Jamin2018/article/details/79060509 https://www.cnblogs.com/lfoder/p/6013142.ht ...

  10. mysql sp 练习游标和预编译

    create procedure Jack_count_cur_dual() BEGIN ); ; DECLARE mycur CURSOR for SELECT table_name FROM tt ...