zoukankan      html  css  js  c++  java
  • HDU

    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>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <cmath>
    
    using namespace std;
    
    const int INF = 0x3f3f3f3f;
    const int MAXN = 910;
    
    struct Edge{
    	int flow,to,rev;
    	Edge(){}
    	Edge(int a,int b,int c):to(a),flow(b),rev(c){}
    };
    
    vector<Edge> E[MAXN];
    
    inline void Add(int from,int to,int flow){
    	E[from].push_back(Edge(to,flow,E[to].size()));
    	E[to].push_back(Edge(from,0,E[from].size()-1));
    }
    
    int deep[MAXN];
    int iter[MAXN];
    
    bool BFS(int from,int to){
    	memset(deep,-1,sizeof deep);
    	deep[from] = 0;
    	queue<int> Q;
    	Q.push(from);
    	while(!Q.empty()){
    		int t = Q.front();
    		Q.pop();
    		for(int i=0 ; i<E[t].size() ; ++i){
    			Edge& e = E[t][i];
    			if(e.flow > 0 && deep[e.to] == -1){
    				deep[e.to] = deep[t] + 1;
    				Q.push(e.to);
    			}
    		}
    	}
    	return deep[to] != -1;
    }
    
    int DFS(int from,int to,int flow){
    	if(from == to || flow == 0)return flow;
    	for(int& i=iter[from] ; i<E[from].size() ; ++i){
    		Edge& e = E[from][i];
    		if(e.flow > 0 && deep[e.to] == deep[from] + 1){
    			int nowflow = DFS(e.to,to,min(flow,e.flow));
    			if(nowflow > 0){
    				e.flow -= nowflow;
    				E[e.to][e.rev].flow += nowflow;
    				return nowflow;
    			}
    		}
    	}
    	return 0;
    }
    
    int Dinic(int from,int to){
    	int sumflow = 0;
    	while(BFS(from,to)){
    		memset(iter,0,sizeof iter);
    		int mid;
    		while((mid = DFS(from,to,INF)) > 0)sumflow += mid;
    	}
    	return sumflow;
    }
    
    int main(){
    	
    	int N,F,D;
    	char s[205];
    	while(scanf("%d %d %d",&N,&F,&D)!=EOF){
    		for(int i=1 ; i<=N ; ++i)Add(i,i+200,1);
    		for(int i=1 ; i<=F ; ++i){
    			int t;
    			scanf("%d",&t);
    			Add(0,i+400,t);
    		}
    		for(int i=1 ; i<=D ; ++i){
    			int t;
    			scanf("%d",&t);
    			Add(i+600,MAXN-1,t);
    		}
    		for(int i=1 ; i<=N ; ++i){
    			scanf("%s",s);
    			for(int j=0 ; j<F ; ++j){
    				if(s[j] == 'Y')Add(j+1+400,i,INF);
    			}
    		}
    		for(int i=1 ; i<=N ; ++i){
    			scanf("%s",s);
    			for(int j=0 ; j<D ; ++j){
    				if(s[j] == 'Y')Add(i+200,j+1+600,INF);
    			}
    		}
    		printf("%d
    ",Dinic(0,MAXN-1));
    		for(int i=0 ; i<MAXN ; ++i)E[i].clear();
    	}
    	
    	return 0;
    } 

  • 相关阅读:
    分离的思想结合单链表实现级联组件:CascadeView
    对jquery的ajax进行二次封装以及ajax缓存代理组件:AjaxCache
    分离与继承的思想实现图片上传后的预览功能:ImageUploadView
    jquery技巧之让任何组件都支持类似DOM的事件管理
    jquery的事件命名空间详解
    多步骤多分步的组件StepJump
    基于sticky组件,实现带sticky效果的tab导航和滚动导航
    sticky组件的改进实现
    从前端性能优化的角度提高自己的博客的访问速度
    ionic serve 突然报错 node-sass
  • 原文地址:https://www.cnblogs.com/vocaloid01/p/9514083.html
Copyright © 2011-2022 走看看