hdu4292 food

辣鸡蒟蒻的blog
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. 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

Source
2012 ACM/ICPC Asia Regional Chengdu Online

Recommend
liuyiding | We have carefully selected several similar problems for you: 4288 4296 4295 4294 4293
弥补一下当年一直tle的遗憾 可能是建图有问题吧
人放中间 拆点限制一下流量 然后左边放食物 源向食物连数量为容量的边 然后右边是饮料 向汇点连数量为容量的边 然后dinic跑一下最大流即可 注意边的数量的计算 双向边我真是zz啊


#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 880
#define inf 0x3f3f3f3f
using namespace std;
struct node{
    int y,z,next;
}data[200*200*5];
int h[N],level[N],n,f,d,T,num=1;
inline void insert1(int x,int y,int z){
    data[++num].y=y;data[num].z=z;data[num].next=h[x];h[x]=num;
    data[++num].y=x;data[num].z=0;data[num].next=h[y];h[y]=num;
}
inline bool bfs(){
    memset(level,0,sizeof(level));level[0]=1;queue<int>q;q.push(0);
    while(!q.empty()){
        int x=q.front();q.pop();
        for (int i=h[x];i;i=data[i].next){
            int y=data[i].y,z=data[i].z;
            if (level[y]||!z) continue;level[y]=level[x]+1;q.push(y);if (y==T) return 1;
        }
    }return 0;
}
inline int dfs(int x,int s){
    if (x==T) return s;int ss=s;
    for (int i=h[x];i;i=data[i].next){
        int y=data[i].y,z=data[i].z;
        if (level[x]+1==level[y]&&z){
            int xx=dfs(y,min(s,z));if (!xx) level[y]=0;
            s-=xx;data[i].z-=xx;data[i^1].z+=xx;if (!s) return ss;
        }
    }return ss-s;
}
int main(){
    freopen("hdu4292.in","r",stdin);
    while(~scanf("%d%d%d",&n,&f,&d)){
        memset(h,0,sizeof(h));num=1;int nn=n<<1;T=n*2+f+d+1;
        for (int i=1;i<=f;++i) {int x;scanf("%d",&x);insert1(0,i,x);}
        for (int i=1;i<=d;++i) {int x;scanf("%d",&x);insert1(f+nn+i,T,x);}
        for (int i=1;i<=n;++i) insert1(f+i,f+n+i,1);
        for (int i=1;i<=n;++i){
            char s[220];scanf("%s",s+1);
            for (int j=1;j<=f;++j) if (s[j]=='Y') insert1(j,f+i,1); 
        }
        for (int i=1;i<=n;++i){
            char s[220];scanf("%s",s+1);
            for (int j=1;j<=d;++j) if (s[j]=='Y') insert1(f+n+i,f+nn+j,1);
        }int ans=0;
        while(bfs()) ans+=dfs(0,inf);printf("%d\n",ans);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值