题目传送门

题目大意:

   给出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. IWebBrowser和IE浏览器的行为不一样

    原本一直以为IWebBrowser2的行为和IE浏览器的行为应该是一样的,但是最近发现事实不是如此. IE8以后的浏览器都带有兼容模式,而IWebBrowser2默认情况下是在兼容模式下运行的,可以参 ...

  2. c语言实践 打印字母三角形

    效果如下: 我是怎么想的: 总共需要打印6行字母,那么就需要一个循环来控制打印第几行,大概代码如下: for(int i=0;i<6;i++) { } 每行都会打印字母,而且循环越往后,需要打印 ...

  3. Apache htdigest命令

    一.简介 htdigest命令是Apache的Web服务器内置工具,用于创建和更新储存用户名.域和用于摘要认证的密码文件.服务器上的资源可以被限制为仅允许由htdigest建立的文件中的用户访问.使用 ...

  4. C# 用代码返回上一页

    若我们在后台.cs文件中想做到让浏览器返回上一页,我们可以在.cs代码中这样写 Page.ClientScript.RegisterStartupScript(Page.GetType(), &quo ...

  5. Struts2获取Action中的数据

    当我们用Struts2框架开发时,经常有要获取jsp页面的数据或者在jsp中获取后台传过来的数据(Action),那么怎么去获取自己想要的数据呢? 后台获取前端数据: 在java程序中生成要获取字段的 ...

  6. java IO 对象流 反序列化和序列化

    例: 重点:需要序列化的对象必须实现Serializable接口 //需要序列化的对象 public class User implements Serializable { private Stri ...

  7. MySQL性能调优与架构设计——第2章 MySQL架构组成

    第2章 MySQL架构组成 前言   麻雀虽小,五脏俱全.MySQL 虽然以简单著称,但其内部结构并不简单.本章从MySQL物理组成.逻辑组成,以及相关工具几个角度来介绍 MySQL 的整体架构组成, ...

  8. XE StringGrid应用(G1属性触发G2)

    unit UnitMain; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System. ...

  9. java 支付宝即时到帐提交订单dome

    package com.tian.batis; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; imp ...

  10. vba实现excel多表合并

    Excel多表合并之vba实现 需求 保留列名,复制每一个excel里的数据,合并到一个excel 操作步骤 将要合并的文件放在同一文件夹下,复制过来就好(ps:最好不要直接操作原数据文件,避免操作失 ...