题目传送门

题目大意:

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

最新文章

  1. 为什么你SQL Server的数据库文件的Date modified没有变化呢?
  2. 我的c++学习(10)this指针
  3. 基于Centos7+Nginx+Tomcat8的负载均衡服务器的搭建
  4. nopCommerce的源代码结构和架构
  5. 调试NodeJS应用
  6. ajax请求aspx页面
  7. div footer标签css实现位于页面底部固定
  8. RMQ(模板 ST 区间最值,频繁的间隔时间)
  9. 简单的jquery实现tab切换
  10. Unix Shortcuts
  11. LeetCode之“动态规划”:Word Break &amp;&amp; Word Break II
  12. 什么是DevOps
  13. 解决MyEclipse启动慢,使用卡顿问题
  14. Linux 驱动——Button驱动2
  15. STM32固件库详解
  16. linux/unix命令参考
  17. iOS手机号,身份证,车牌号正则表达式
  18. (2)R中的数据类型和数据结构
  19. 关于 javascript:void(0) 的问题.
  20. CF464C-Substitutes in Number

热门文章

  1. php+mysql网站无限级栏目分类-递归获取树形结构函数
  2. solr第二天 京东案例
  3. Python3 BeautifulSoup和Pyquery解析库随笔
  4. memcpy用法
  5. js 判断今天是否上班
  6. C#向服务器上传文件问题
  7. T-SQL查询进阶--理解SQL Server中索引的概念,原理
  8. Android Studio无法找到tool.jar解决方法!
  9. NSTimeZone时区
  10. Linux环境下jdk、tomcat、redis安装及配置