Alice's Chance
id=1698" style="background-color:rgb(51,255,51)">主题链接
- 意甲冠军:
爱丽丝要拍电影。有n部电影,规定爱丽丝第i部电影在每一个礼拜仅仅有固定的几天能够拍电影,且仅仅能在前wi个周拍,而且这部电影要拍di天才干结束。问爱丽丝能不能拍全然部的电影
第一行代表有多少组数据,对于每组数据第一行代表有n部电影,接下来2到n+1行,每行代表一个电影,每行9个数,前面7个数,1代表拍。0代表不拍,第8个数代表要拍几天,第9个数代表有几个礼拜时间拍 - 分析:
对于每一个电影。di - x[0] - x[1] - ... - x[t] = 0,di表示这个电影须要的天数,x[]表示电影相应的这些天是否选择(取值为零或一)
对于每一天。y[0] - y[1] - ... - y[t] <= 1,1表示这一天最多拍一个电影。y[]表示相应的电影是否在这一天拍(取值为零或一)
struct Edge
{
int from, to, cap, flow;
bool operator< (const Edge& rhs) const
{
return from < rhs.from || (from == rhs.from && to < rhs.to);
}
}; const int MAXV = 500;
struct ISAP
{
int n, m, s, t;
vector<Edge> edges;
vector<int> G[MAXV]; // 邻接表。G[i][j]表示结点i的第j条边在e数组中的序号
bool vis[MAXV]; // BFS使用
int d[MAXV]; // 从起点到i的距离
int cur[MAXV]; // 当前弧指针
int p[MAXV]; // 可增广路上的上一条弧
int num[MAXV]; // 距离标号计数 void AddEdge(int from, int to, int cap)
{
edges.push_back((Edge) { from, to, cap, 0 });
edges.push_back((Edge) { to, from, 0, 0 });
m = edges.size();
G[from].push_back(m-2);
G[to].push_back(m-1);
} bool BFS()
{
memset(vis, 0, sizeof(vis));
queue<int> Q;
Q.push(t);
vis[t] = 1;
d[t] = 0;
while(!Q.empty())
{
int x = Q.front();
Q.pop();
REP(i, G[x].size())
{
Edge& e = edges[G[x][i]^1];
if(!vis[e.from] && e.cap > e.flow)
{
vis[e.from] = 1;
d[e.from] = d[x] + 1;
Q.push(e.from);
}
}
}
return vis[s];
} void ClearAll(int n)
{
this->n = n;
REP(i, n)
G[i].clear();
edges.clear();
} void ClearFlow()
{
REP(i, edges.size())
edges[i].flow = 0;
} int Augment()
{
int x = t, a = INF;
while(x != s)
{
Edge& e = edges[p[x]];
a = min(a, e.cap-e.flow);
x = edges[p[x]].from;
}
x = t;
while(x != s)
{
edges[p[x]].flow += a;
edges[p[x]^1].flow -= a;
x = edges[p[x]].from;
}
return a;
} int Maxflow(int s, int t, int need)
{
this->s = s;
this->t = t;
int flow = 0;
BFS();
memset(num, 0, sizeof(num));
REP(i, n) num[d[i]]++;
int x = s;
memset(cur, 0, sizeof(cur));
while(d[s] < n)
{
if(x == t)
{
flow += Augment();
if(flow >= need) return flow;
x = s;
}
int ok = 0;
FF(i, cur[x], G[x].size())
{
Edge& e = edges[G[x][i]];
if(e.cap > e.flow && d[x] == d[e.to] + 1) // Advance
{
ok = 1;
p[e.to] = G[x][i];
cur[x] = i; // 注意
x = e.to;
break;
}
}
if(!ok) // Retreat
{
int m = n-1; // 初值注意
REP(i, G[x].size())
{
Edge& e = edges[G[x][i]];
if(e.cap > e.flow)
m = min(m, d[e.to]);
}
if(--num[d[x]] == 0)
break;
num[d[x] = m + 1]++;
cur[x] = 0; // 注意
if(x != s)
x = edges[p[x]].from;
}
}
return flow;
} vector<int> Mincut() // call this after maxflow
{
BFS();
vector<int> ans;
REP(i, edges.size())
{
Edge& e = edges[i];
if(!vis[e.from] && vis[e.to] && e.cap > 0)
ans.push_back(i);
}
return ans;
} void Reduce()
{
REP(i, edges.size())
edges[i].cap -= edges[i].flow;
} void print()
{
printf("Graph:\n");
REP(i, edges.size())
printf("%d->%d, %d, %d\n", edges[i].from, edges[i].to , edges[i].cap, edges[i].flow);
}
} mf; int day[18]; int main()
{
int T, n, d, w;
RI(T);
FE(kase, 1, T)
{
int sum = 0;
RI(n);
mf.ClearAll(n + 7 * 50 + 2);
int S = 0, T = n + 7 * 50 + 1, Max = -1;
FE(i, 1, n)
{
FE(j, 1, 7)
RI(day[j]);
RII(d, w);
sum += d;
Max = max(Max, w);
mf.AddEdge(S, i, d);
FE(j, 1, 7)
if (day[j])
{
REP(k, w)
mf.AddEdge(i, n + k * 7 + j, 1);
}
}
FE(i, 1, 7) REP(j, Max)
mf.AddEdge(n + j * 7 + i, T, 1);
printf("%s\n", mf.Maxflow(S, T, INF) == sum ? "Yes" : "No");
}
return 0;
}
版权声明:本文博主原创文章,博客,未经同意不得转载。
Alice's Chance的更多相关文章
- POJ 1698 Alice's Chance(最大流+拆点)
POJ 1698 Alice's Chance 题目链接 题意:拍n部电影.每部电影要在前w星期完毕,而且一周仅仅有一些天是能够拍的,每部电影有个须要的总时间,问能否拍完电影 思路:源点向每部电影连边 ...
- poj 1698 Alice's Chance 拆点最大流
将星期拆点,符合条件的连边,最后统计汇点流量是否满即可了,注意结点编号. #include<cstdio> #include<cstring> #include<cmat ...
- HDU 4791 & ZOJ 3726 Alice's Print Service (数学 打表)
题目链接: HDU:http://acm.hdu.edu.cn/showproblem.php?pid=4791 ZJU:http://acm.zju.edu.cn/onlinejudge/showP ...
- HDU 4791 Alice's Print Service 水二分
点击打开链接 Alice's Print Service Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- hdu 4122 Alice's mooncake shop (线段树)
题目大意: 一个月饼店每一个小时做出月饼的花费不一样. 储存起来要钱.最多存多久.问你把全部订单做完的最少花费. 思路分析: ans = segma( num[]*(cost[] + (i-j)*s) ...
- 2-sat(石头、剪刀、布)hdu4115
Eliminate the Conflict Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- hdu 4115 Eliminate the Conflict ( 2-sat )
Eliminate the Conflict Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- hdu4115 Eliminate the Conflict
Eliminate the Conflict Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- Spark GraphX实例(2)
5. 图的转换操作 图的转换操作主要有以下的方法: (1) Graph.mapVertices():对图的顶点进行转换,返回一张新图: (2) Graph.mapEdges():对图的边进行转换,返回 ...
随机推荐
- ubuntu快捷键设置,查看系统
设置system setting于.点击键盘keyboard,有捷径keyboard shortcut.但也设置快捷键本身. 版权声明:本文博主原创文章,博客,未经同意不得转载.
- 开源Math.NET基础数学类库使用(02)矩阵向量计算
原文:[原创]开源Math.NET基础数学类库使用(02)矩阵向量计算 开源Math.NET基础数学类库使用系列文章总目录: 1.开源.NET基础数学计算组件Math.NET(一)综合介绍 ...
- leetcode第一刷_Minimum Path Sum
能够用递归简洁的写出,可是会超时. dp嘛.这个问题须要从后往前算,最右下角的小规模是已知的,边界也非常明显,是最后一行和最后一列,行走方向的限制决定了这些位置的走法是唯一的,能够先算出来.然后不断的 ...
- 追索权 Eclipse + NDK error: stray '\24' in program
[size=16px][b][color=#FF0000]追索权 Eclipse + NDK error: stray '\24' in program[/color][b][/b][/b][/si ...
- Visual Studio中开发
如何在Visual Studio中开发自己的代码生成器插件 Visual Studio是美国微软公司开发的一个基本完整的开发工具集,它包括了整个软件生命周期中所需要的大部分工具,如UML工具.代 ...
- LeetCode Solutions : Reorder List
→-→Ln-1→Ln, reorder it to: L→Ln-2→- You must do this in-place without altering the nodes' values. Fo ...
- struts2和struts1认识
1.Struts 2基本流程 Struts 2框架本身可以大致分3部分:核心控制器FilterDispatcher.业务总监Action与用户实现企业业务逻辑组件. 核心控制器FilterDispat ...
- POJ 3237 Tree (树链拆分)
主题链接~~> 做题情绪:了. 解题思路: 主要注意如何区间更新就ok了 . 树链剖分就是树上的线段树. 代码: #include<iostream> #include<sst ...
- WPF学习(5)依赖属性
今天我们来学习WPF一个比较重要的概念:依赖属性.这里推荐大家看看周永恒大哥的文章,讲的确实很不错.我理解的没那么深入,只能发表一下自己的浅见.提到依赖属性,不得不说我们经常使用的传统的.net属性, ...
- [WebGL入门]四,渲染准备
注意:文章翻译http://wgld.org/,原作者杉本雅広(doxas),文章中假设有我的额外说明,我会加上[lufy:].另外.鄙人webgl研究还不够深入,一些专业词语,假设翻译有误,欢迎大家 ...