# 小猪分配 ， 最大流

Mirko works on a pig farm that consists of M locked pig-houses and Mirko can‘t unlock any pighouse because he doesn‘t have the keys. Customers come to the farm one after another. Each of them has keys to some pig-houses and wants to buy a certain number of pigs.
All data concerning customers planning to visit the farm on
that particular day are available to Mirko early in the morning so that
he can make a sales-plan in order to maximize the number of pigs sold.

More precisely, the procedure is as following: the customer
arrives, opens all pig-houses to which he has the key, Mirko sells a
certain number of pigs from all the unlocked pig-houses to him, and, if
Mirko wants, he can redistribute the remaining pigs across the unlocked
pig-houses.

An unlimited number of pigs can be placed in every pig-house.

Write a program that will find the maximum number of pigs that he can sell on that day.

Input

The first line of input contains two integers M and N, 1 <= M
<= 1000, 1 <= N <= 100, number of pighouses and number of
customers. Pig houses are numbered from 1 to M and customers are
numbered from 1 to N.

The next line contains M integeres, for each pig-house
initial number of pigs. The number of pigs in each pig-house is greater
or equal to 0 and less or equal to 1000.

The next N lines contains records about the customers in the
following form ( record about the i-th customer is written in the
(i+2)-th line):

A K1 K2 ... KA B It means that this customer has key to the
pig-houses marked with the numbers K1, K2, ..., KA (sorted
nondecreasingly ) and that he wants to buy B pigs. Numbers A and B can
be equal to 0.

Output

The first and only line of the output should contain the number of sold pigs.

Sample Input

```3 3
3 1 10
2 1 2 2
2 1 3 3
1 2 6```

Sample Output

```7

```const int maxn = 1e4+5;
const int inf = 0x3f3f3f3f;

int m, n;
int a;
vector<int>ve;
struct node
{
int to, flow;
int next;
}e[maxn];
int cnt = 0;
int s, t;

void addedge(int u, int v, int w){
e[cnt].next = head[u], e[cnt].to = v, e[cnt].flow = w, head[u] = cnt++;
e[cnt].next = head[v], e[cnt].to = u, e[cnt].flow = 0, head[v] = cnt++;
}
int belong;
int dep, que[maxn];

bool bfs(int s, int t){
int head1 = 0, tail = 1;
memset(dep, 0, sizeof(dep));
que = s; dep[s] = 1;
int v = que[head1++];
for(int i = head[v]; i != -1; i = e[i].next){
int to = e[i].to;
if (e[i].flow && !dep[to]) {
dep[to] = dep[v]+1;
que[tail++] = to;
}
}
}
return dep[t];
}
int dfs(int u, int f1){
if (f1 == 0 || u == t) return f1;

int f = 0;
for(int i = head[u]; i != -1; i = e[i].next){
int to = e[i].to;
if (e[i].flow && dep[to] == dep[u]+1){
int x = dfs(to, min(e[i].flow, f1));
e[i].flow -= x; e[i^1].flow += x;
f1 -= x, f += x;
if (f1 == 0) return f;
}
}
if (!f) dep[u] = -2;
return f;
}

int maxflow(int s, int t){
int ans = 0;
while(bfs(s, t)){
ans += dfs(s, inf);
}
return ans;
}

int main() {
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
int x, y;
cin >> m >> n;
s = 0, t = n+1;
for(int i = 1; i <= m; i++) scanf("%d", &a[i]);
for(int i = 1; i <= n; i++){
scanf("%d", &x);
for(int j = 1; j <= x; j++) {
scanf("%d", &y);
ve[i].push_back(y);
}
scanf("%d", &y);
}
for(int i = 1; i <= n; i++){
for(int j = 0; j < ve[i].size(); j++){
int v = ve[i][j];
if (!belong[v]) {
belong[v] = i;
}
else {
belong[v] = i;
}
}
}
printf("%d\n", maxflow(s, t));
return 0;
}
```

## socket计划编制的原则 socket编程原理 1.问题的引入 1) 普通的I/O操作过程: UNIX系统的I/O命令集,是从Maltics和早期系统中的命令演变出来的,其模式为打开一读/写一关闭(open-write-read-close).在一个用户进程进行I/O操作时,它首先调用"打开"获得对指定文件或设备的使用权,并返回称为文件描写叙述符的整型数,以描写叙述用户在打开的文件或设备上进行I/O操作的进程.然后这个用户进程多次调用"读/写"以数据传输.当全部的传输操作完毕后,用户进程关闭

## 文件创建读取 删除 ## 基本的TCP套接字编程 ## Java中I/O流之数据流

Java 中的数据流: 对于某问题:将一个 long 类型的数据写到文件中,有办法吗?    转字符串 → 通过 getbytes() 写进去,费劲,而且在此过程中 long 类型的数需要不断地转换. 现在,Java 中的数据流能够很好的解决这个问题(不需要转换,直接写进去) 1. DataInputStream 与 DataOutputStream 分别继承自 InputStream.OutputStream, 它属于处理流,需要分别套接在 InputStream.OutputStream 类