HDU4292--Food

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. �e 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. �e 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

 

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define maxn 2007//这是点数
#define edge  100*maxn
#define inf 0x3f3f3f3f
int N, F, D;
struct Adj
{
	int v,w,next;
	Adj(){}
	Adj(int vv,int ww,int nxt)
	{
		v = vv;
		w = ww;
		next = nxt;
	}
}adj[edge];
int first[maxn];
int cnt,NN;
int dis[maxn],num[maxn];
void addEdge(int u,int v,int w)
{
	adj[cnt] = Adj(v,w,first[u]);
	first[u] = cnt++;
	adj[cnt] = Adj(u,0,first[v]);
	first[v] = cnt++;
}
inline int min(int a,int b)
{
	return a>b?b:a;
}
int dfs(int u,int s,int d,int cost)
{
	if(u == d) return cost;
	int ans = 0;
	int _min = NN;//总点数
	for(int i=first[u];i!=-1;i=adj[i].next)
	{
		int v = adj[i].v;
		if(adj[i].w)
		{
			if(dis[v] + 1 == dis[u])
			{
				int t = dfs(v,s,d,min(adj[i].w,cost));
				adj[i].w -= t;
				adj[i^1].w += t;
				ans += t;
				cost -= t;
				if(dis[s] == NN) return ans;
				if(!cost) break;
			}
			if(_min > dis[v])
				_min = dis[v];
		}
	}
	if(!ans)
	{
		if(--num[dis[u]] == 0) dis[s] = NN;
		dis[u] = _min + 1;
		++ num[dis[u]];
	}
	return ans;
}
int isap(int s,int d)
{
	memset(dis,0,sizeof(dis));
	memset(num,0,sizeof(num));
	num[0] = NN;
	int ans = 0;
	while(dis[s] < NN)
		ans += dfs(s,s,d,inf);
	return ans;
}
 int main() 
 { 
     //freopen("e://data.in", "r", stdin); 
     while(scanf("%d%d%d", &N, &F, &D) != EOF) 
     { 
         int i, j; 
         int a; 
         char s[maxn]; 
         memset(first, -1, sizeof(first)); 
         cnt = 0; 
         for(i = 1; i <= F; ++ i)  
         { 
             scanf("%d", &a); 
             addEdge(0, i, a); 
         } 
         for(i = 1; i <= D; ++ i) 
         { 
             scanf("%d", &a); 
             addEdge(F + 2 * N + i, F + 2 * N + D + 1, a); 
         } 
         for(i = 1; i <= N; ++ i) 
         { 
             addEdge(F + i, F + N + i, 1); 
         } 
         for(i = 1; i <= N; ++ i) 
         { 
             scanf("%s", s + 1); 
             for(j = 1; j <= F; ++ j) 
                 if(s[j] == 'Y') 
                     addEdge(j, F + i, inf); 
         } 
         for(i = 1; i <= N; ++ i) 
         { 
             scanf("%s", s + 1); 
             for(j = 1; j <= D; ++ j) 
                 if(s[j] == 'Y') 
                     addEdge(F + N + i, F + 2 * N + j, inf); 
         } 
         NN = F + 2 * N + D + 2; 
         int ans = isap(0, NN - 1); 
         printf("%d\n", ans); 
     } 
     return 0; 
 } 


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值