【题目链接】

【JZXX】点击打开链接

【caioj】点击打开链接

【算法】

拆点+网络流

【代码】

#include<bits/stdc++.h>
using namespace std;
#define MAXN 1000 int i,tot,N,F,D,sf,sd,ans,x;
int U[MAXN*],V[MAXN*],W[MAXN*],Head[MAXN*],
Next[MAXN*],other[MAXN*],h[MAXN*]; template <typename T> void read(T &x) {
int f=; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) { if (c=='-') f=-; }
for (; isdigit(c); c = getchar()) x=x*+c-'';
x*=f;
} inline void add(int a,int b,int c) {
++tot;
U[tot] = a; V[tot] = b; W[tot] = c;
Next[tot] = Head[a]; Head[a] = tot;
other[tot] = tot + ;
++tot;
U[tot] = b; V[tot] = a; W[tot] = ;
Next[tot] = Head[b]; Head[b] = tot;
other[tot] = tot - ;
} inline bool BFS() {
int i,x,y;
queue<int> q;
memset(h,,sizeof(h));
h[] = ; q.push();
while (!q.empty()) {
x = q.front(); q.pop();
for (i = Head[x]; i; i = Next[i]) {
y = V[i];
if ((W[i] > ) && (!h[y])) {
h[y] = h[x] + ;
q.push(y);
}
}
}
if (h[F+*N+D+]) return true;
else return false;
} int maxflow(int x,int f) {
int i,y,s=,t;
if (x == F + * N + D + ) return f;
for (i = Head[x]; i; i = Next[i]) {
y = V[i];
if ((W[i] > ) && (h[y] == h[x] + ) && (s < f)) {
s += (t = maxflow(y,min(W[i],f-s)));
W[i] -= t; W[other[i]] += t;
}
}
if (!s) h[x] = ;
return s;
} int main() { read(N); read(F); read(D);
for (i = ; i <= F; i++) add(,+i,);
for (i = ; i <= D; i++) add(+F+*N+i,F+*N+D+,);
for (i = ; i <= N; i++) add(+F+i,+F+N+i,);
for (i = ; i <= N; i++) {
read(sf); read(sd);
while (sf--) {
read(x);
add(+x,i+F+,);
}
while (sd--) {
read(x);
add(+F+N+i,+F+*N+x,);
}
} while (BFS()) {
ans += maxflow(,2e9);
} cout<< ans << endl; return ; }

【USACO】Dining的更多相关文章

  1. POJ 1986 Distance Queries / UESTC 256 Distance Queries / CJOJ 1129 【USACO】距离咨询(最近公共祖先)

    POJ 1986 Distance Queries / UESTC 256 Distance Queries / CJOJ 1129 [USACO]距离咨询(最近公共祖先) Description F ...

  2. 1642: 【USACO】Payback(还债)

    1642: [USACO]Payback(还债) 时间限制: 1 Sec 内存限制: 64 MB 提交: 190 解决: 95 [提交] [状态] [讨论版] [命题人:外部导入] 题目描述 &quo ...

  3. 1519: 【USACO】超级书架

    1519: [USACO]超级书架 时间限制: 1 Sec 内存限制: 64 MB 提交: 1735 解决: 891 [提交] [状态] [讨论版] [命题人:外部导入] 题目描述 Farmer Jo ...

  4. Java实现【USACO】1.1.2 贪婪的礼物送礼者 Greedy Gift Givers

    [USACO]1.1.2 贪婪的礼物送礼者 Greedy Gift Givers 题目描述 对于一群要互送礼物的朋友,你要确定每个人送出的礼物比收到的多多少(and vice versa for th ...

  5. 【CPLUSOJ】【USACO】【差分约束】排队(layout)

    [题目描述] Robin喜欢将他的奶牛们排成一队.假设他有N头奶牛,编号为1至N.这些奶牛按照编号大小排列,并且由于它们都很想早点吃饭,于是就很可能出现多头奶牛挤在同一位置的情况(也就是说,如果我们认 ...

  6. 【USACO】Optimal Milking

    题目链接 :        [POJ]点击打开链接        [caioj]点击打开链接 算法 : 1:跑一遍弗洛伊德,求出点与点之间的最短路径 2:二分答案,二分”最大值最小“ 3.1:建边,将 ...

  7. 【USACO】 Balanced Photo

    [题目链接] 点击打开链接 [算法] 树状数组 [代码] #include<bits/stdc++.h> using namespace std; int i,N,ans,l1,l2; ] ...

  8. 【USACO】 Balanced Lineup

    [题目链接] 点击打开链接 [算法] 这是一道经典的最值查询(RMQ)问题. 我们首先想到线段树.但有没有更快的方法呢?对于这类问题,我们可以用ST表(稀疏表)算法求解. 稀疏表算法.其实也是一种动态 ...

  9. 【USACO】The Cow Prom

    [题目链接] 点击打开链接 [算法] tarjan求强连通分量 [代码] #include<bits/stdc++.h> #define MAXN 20005 using namespac ...

随机推荐

  1. cache数据库之表的存储结构

    1.我们已经建了一个person类,接下来就是表的存储结构 2.打开Inspector,先输入rowid名字为p_RowID,选class->Storage 3.新建一个Storage,选择Ca ...

  2. (一)MVVMLight安装

    http://www.cnblogs.com/manupstairs/p/4890300.html 1.首先新建一个wpf项目 2. 安装完成即可在我们的项目中看到如下引用: 如果点击安装的时候出现: ...

  3. LeetCode85 Maximal Rectangle java题解

    public static int maximalRectangle(char[][] matrix) { int rowNum=matrix.length; if(rowNum==0) return ...

  4. RSA、AES加密解密

    RSA #!/usr/bin/env python # -*- coding:utf-8 -*- import rsa import base64 # ######### 1. 生成公钥私钥 #### ...

  5. Ajax 跨域难题 - 原生 JS 和 jQuery 的实现对比

    讲解顺序: AJAX 的概念及由来 JS 和 jQuery 中的 ajax 浏览器机制 AJAX 跨域 AJAX 的概念 在讲解 AJAX 的概念之前,我先提一个问题. 这是一个典型的 B/S 模式. ...

  6. hdu 1081 &amp; poj 1050 To The Max(最大和的子矩阵)

    转载请注明出处:http://blog.csdn.net/u012860063 Description Given a two-dimensional array of positive and ne ...

  7. 7.JAVA编程思想笔记隐藏实施过程

    欢迎转载,转载请标明出处:http://blog.csdn.net/notbaron/article/details/51040237 "进行面向对象的设计时,一项主要的考虑是:怎样将发生变 ...

  8. shell grep正则匹配汉字

    Shell grep正则匹配中文 测试文本 demo_exe.c,内容如下,需要注意保存的编码格式,对输出到终端有影响: 我们中文操作系统ASNI默认是GBK的. #include<stdio. ...

  9. 汇率换算自然语言理解功能JAVA DEMO

    >>>>>>>>>>>>>>>>>>>>>>>> 欢迎转 ...

  10. 如何设置快捷键(File Search)

    window->preferences->General->keys. 找到File Search(有搜索框的,可以搜索),然后在下方 Binding按下ctrl +h .