题目传送门

题目大意:

   给出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. XP下,移动窗口产生重影的问题

    最近做了一个东西,其中有一个小窗口需要跟着主窗口一起移动,结果发现在Xp系统上总是产生重影,需要刷新桌面才能消失. 移动窗口我使用的是MoveWindow,最后一个参数bRepaint传递的是FALS ...

  2. cocos2D-x demo 的源码分析 #define ..##.. 的妙用.

    最近在看cocos2d-x 但不知道如何下手,于是先看一下他编译的完成的testcpp的源码.发现了下面一段程序 typedef CCLayer* (*NEWTESTFUNC)(); #define ...

  3. hadoop搭建好,启动服务后,无法从web界面访问50070

    在hadoop完全分布式搭建好以后,从主节点启动正常,使用jps查看启动的进程,正常,在几个从节点上使用jps查看,显示正常,但从web上输入下面网址: http://主节点IP:50070 无法正常 ...

  4. ROS 下使用3D激光雷达 velodyne vlp-16

    Velodyne VLP16型激光雷达横向视角360°,纵向视角30° 系统和ROS版本:Ubuntu 14.04 ,ros indigo 1. 安装驱动 sudo apt-get install r ...

  5. list 的扩展

    数据挖掘中会遇到添加多个新的特征s,对一个feature = list()来说, 除了可以用 feature.append('xx') # 在尾部添加一个特征 feature.extend(['xx' ...

  6. 僵固式思维 OR 成长式思维

    有意无意中,看到这样的一篇文章,觉得非常富有正能量,而且也比较有同感.而且,不仅仅对于职场暂时失落或者失意的人有帮助,就是对学生,也一样的.故特分享,以共勉之. 我想每个新人进入职场之后都会遇到的第一 ...

  7. Install zlib/libpng/jpeg/freetype/libgd/GD on Mavericks即mac10.9(转)

    转自:http://wangqinhu.com/install-gd-on-mavericks/ Various applications depend on library GD, however, ...

  8. C++语法知识小结(持续更新中)

    1)在适用构造函数创建对象时,有时会创建临时对象.如 Stock::Stock(const std::string & co,long n,double pr); 在使用时,下面两条语句有根本 ...

  9. JAVA8 Lambda 表达式使用心得

    List<HashMap> 指定数据求和: List<HashMap> kk = new ArrayList<>();        Map mmm = new H ...

  10. C#Async,await异步简单介绍

    C# 5.0 引入了async/await,.net framework4.5开始支持该用法 使用: 由async标识的方法必须带有await,如果不带await,方法将被同步执行 static vo ...