日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

HDU Problem - 4292 Food(最大流, 建边)

發(fā)布時間:2024/4/18 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDU Problem - 4292 Food(最大流, 建边) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題目鏈接

Problem Description

  You, a part-time dining service worker in your college’s dining hall, are now confused with a new problem: serve as many people as possible.  The issue comes up as people in your college are more and more difficult to serve with meal: They eat only some certain kinds of food and drink, and with requirement unsatisfied, go away directly.  You have prepared F (1 <= F <= 200) kinds of food and D (1 <= D <= 200) kinds of drink. Each kind of food or drink has certain amount, that is, how many people could this food or drink serve. Besides, You know there’re N (1 <= N <= 200) people and you too can tell people’s personal preference for food and drink.  Back to your goal: to serve as many people as possible. So you must decide a plan where some people are served while requirements of the rest of them are unmet. You should notice that, when one’s requirement is unmet, he/she would just go away, refusing any service.

Input

  There are several test cases.  For each test case, the first line contains three numbers: N,F,D, denoting the number of people, food, and drink.  The second line contains F integers, the ith number of which denotes amount of representative food.  The third line contains D integers, the ith number of which denotes amount of representative drink.  Following is N line, each consisting of a string of length F. �阤 jth character in the ith one of these lines denotes whether people i would accept food j. “Y” for yes and “N” for no.  Following is N line, each consisting of a string of length D. �阤 jth character in the ith one of these lines denotes whether people i would accept drink j. “Y” for yes and “N” for no.  Please process until EOF (End Of File).

Output

  For each test case, please print a single line with one integer, the maximum number of people to be satisfied.

Sample Input

4 3 3 1 1 1 1 1 1 YYN NYY YNY YNY YNY YYN YYN NNY

Sample Output

3

AC

  • 建邊
  • 源點到食物,權(quán)值為數(shù)量
  • 食物到人,權(quán)值為inf
  • 人到(拆點人),權(quán)值為1(保證不會浪費,同一個人得到多個)
  • 拆點人到飲料,權(quán)值為inf
  • 飲料到匯點,權(quán)值為數(shù)量
#include <iostream> #include <stdio.h> #include <map> #include <vector> #include <queue> #include <algorithm> #include <cmath> #define N 162000 #include <cstring> #define ll long long #define P pair<int, int> #define mk make_pair using namespace std; int head[810], curedge[810], level[810]; int inf = 0x3f3f3f3f; int n, f, d, cnt; struct ac{int v, c, pre; }edge[N]; void init() {cnt = 0;memset(head, -1, sizeof(head));memset(edge, 0, sizeof(edge)); } void addedge(int u, int v, int c) {edge[cnt].v = v;edge[cnt].c = c;edge[cnt].pre = head[u];head[u] = cnt++;swap(u, v); edge[cnt].v = v;edge[cnt].c = 0;edge[cnt].pre = head[u];head[u] = cnt++; }bool bfs(int s, int e) {queue<int> que;memset(level, 0, sizeof(level));level[s] = 1;que.push(s);while (!que.empty()) {int u = que.front();que.pop();for (int i = head[u]; i != -1; i = edge[i].pre) {if (level[edge[i].v] || edge[i].c <= 0) continue;level[edge[i].v] = level[u] + 1;que.push(edge[i].v);}}return level[e] != 0; } int dfs(int s, int e, int flow) {if (s == e) return flow;for (int &i = curedge[s]; i != -1; i = edge[i].pre) {if (level[edge[i].v] == level[s] + 1 && edge[i].c > 0) {int d = dfs(edge[i].v, e, min(flow, edge[i].c));if (d > 0) {edge[i].c -= d;edge[i ^ 1].c += d;return d;}}}return 0; } int Dinic(int s, int e) {int sum = 0;while (bfs(s, e)) {for (int i = 0; i <= e; ++i) {curedge[i] = head[i];}int d;while (d = dfs(s, e, inf)) {sum += d;}}return sum; } int main() { #ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin); #endifwhile (scanf("%d%d%d", &n, &f, &d) != EOF) {init();int start = 0, end = f + n + n + d + 1;// 源點到食物 for (int i = 1; i <= f; ++i) {int t;scanf("%d", &t);addedge(start, i, t);}// 飲料到匯點 for (int j = 1; j <= d; ++j) {int t;scanf("%d", &t);addedge(f + n * 2 + j, end, t);}getchar();// 食物到人 for (int i = 1; i <= n; ++i) {char c;for (int j = 1; j <= f; ++j) {scanf("%c", &c);if (c == 'Y') {addedge(j, f + i, inf);} }getchar();}// 人到飲料 for (int i = 1; i <= n; ++i) {char c;for (int j = 1; j <= d; ++j) {scanf("%c", &c);if (c == 'Y') {addedge(f + n + i, f + n + n + j, inf);}}getchar();}// 拆點的同一個人之間建邊 for (int i = 1; i <= n; ++i) {addedge(f + i, f + n + i, 1);}int ans = Dinic(start, end);printf("%d\n", ans);}return 0; }

總結(jié)

以上是生活随笔為你收集整理的HDU Problem - 4292 Food(最大流, 建边)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。