设为首页 加入收藏

TOP

HDU 3829 Cat VS Dog ( 最大独立集 = 顶点数 - 最大匹配数)
2014-11-23 21:46:33 来源: 作者: 【 】 浏览:12
Tags:HDU 3829 Cat Dog 最大 独立 点数 匹配
Cat VS Dog
Time Limit: 2000/1000 MS ( Java/Others) Memory Limit: 125536/65536 K (Java/Others)
Total Submission(s): 2148 Accepted Submission(s): 748
Problem Description
The zoo have N cats and M dogs, today there are P children visiting the zoo, each child has a like-animal and a dislike-animal, if the child's like-animal is a cat, then his/hers dislike-animal must be a dog, and vice versa.
Now the zoo administrator is removing some animals, if one child's like-animal is not removed and his/hers dislike-animal is removed, he/she will be happy. So the administrator wants to know which animals he should remove to make maximum number of happy children.
Input
The input file contains multiple test cases, for each case, the first line contains three integers N <= 100, M <= 100 and P <= 500.
Next P lines, each line contains a child's like-animal and dislike-animal, C for cat and D for dog. (See sample for details)
Output
For each case, output a single integer: the maximum number of happy children.
Sample Input
1 1 2
C1 D1
D1 C1
1 2 4
C1 D1
C1 D1
C1 D2
D2 C1
Sample Output
1
3
题意:动物园有 N只猫,M只狗,有P个小孩去动物园,现在动物管理员,移除小孩不喜欢的而动物,最多可以使多少个小孩高兴。
思路:建立完二分图之后,相当于求二分图的最大独立集 = 顶点数 - 最大匹配数。
import java.io.*;  
import java.util.*;  
public class Main {  
    int n,m,p;  
    int[][] map;  
    int[] link=new int[600];  
    boolean[] mark=new boolean[600];  
    public static void main(String[] args) {  
        new Main().work();  
    }  
    void work(){  
        Scanner sc=new Scanner(new BufferedInputStream(System.in));  
        while(sc.hasNext()){  
            n=sc.nextInt();  
            m=sc.nextInt();  
            p=sc.nextInt();  
            Node node[]=new Node[p];  
            map=new int[600][600];  
            for(int i=0;i 
  


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇poj 3271 Lilypad Pond bfs 下一篇UVA 10716 Evil Straw Warts Live..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·深入理解 Java 集合 (2025-12-27 07:22:48)
·Java集合框架全面解 (2025-12-27 07:22:45)
·时隔 15 年,巨著《J (2025-12-27 07:22:43)
·定义一个类模板并实 (2025-12-27 06:52:28)
·一文搞懂怎么用C语言 (2025-12-27 06:52:25)