POJ1469_COURSES(二部图最大匹配)

POJ1469_COURSES(二部图最大匹配)

大家好,又见面了,我是全栈君,今天给大家准备了Idea注册码。

解决报告

http://blog.csdn.net/juncoder/article/details/38136065

题目传送门

题意:

n个学生p门课程,每一个学生学习0或1以上的课程。

问:能否够组成委员会。满足

每一个学生代表一门不同的课程

一门课程在委员会中有一名代表

思路:

非常明显的二分图的完备匹配。

#include <map>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#define N 330
#define P 110
using namespace std;
int mmap[N+P][N+P],n,p,pre[N+P],vis[N+P],m,k;
int dfs(int x)
{
    for(int i=p+1;i<=p+n;i++)
    {
        if(!vis[i]&&mmap[x][i])
        {
            vis[i]=1;
            if(pre[i]==-1||dfs(pre[i]))
            {
                pre[i]=x;
                return 1;
            }
        }
    }
    return 0;
}
int main()
{
    int i,j,t;
    while(~scanf("%d",&t))
    {
        while(t--)
        {
            memset(mmap,0,sizeof(mmap));
            memset(pre,-1,sizeof(pre));
            scanf("%d%d",&p,&n);
            for(i=1;i<=p;i++)
            {
                scanf("%d",&m);
                for(j=1;j<=m;j++)
                {
                    scanf("%d",&k);
                    mmap[i][k+p]=1;
                }
            }
            int ans=0;
            for(i=1;i<=p;i++)
            {
                memset(vis,0,sizeof(vis));
                ans+=dfs(i);
            }
            if(ans==p)
            printf("YES\n");
            else printf("NO\n");
        }
    }
    return 0;
}

COURSES
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 17166   Accepted: 6748

Description

Consider a group of N students and P courses. Each student visits zero, one or more than one courses. Your task is to determine whether it is possible to form a committee of exactly P students that satisfies simultaneously the conditions: 

  • every student in the committee represents a different course (a student can represent a course if he/she visits that course) 
  • each course has a representative in the committee 

Input

Your program should read sets of data from the std input. The first line of the input contains the number of the data sets. Each data set is presented in the following format: 

P N 

Count1 Student
1 1 Student
1 2 … Student
1 Count1 

Count2 Student
2 1 Student
2 2 … Student
2 Count2 

… 

CountP Student
P 1 Student
P 2 … Student
P CountP 

The first line in each data set contains two positive integers separated by one blank: P (1 <= P <= 100) – the number of courses and N (1 <= N <= 300) – the number of students. The next P lines describe in sequence of the courses �from course 1 to course P, each line describing a course. The description of course i is a line that starts with an integer Count i (0 <= Count i <= N) representing the number of students visiting course i. Next, after a blank, you抣l find the Count i students, visiting the course, each two consecutive separated by one blank. Students are numbered with the positive integers from 1 to N. 

There are no blank lines between consecutive sets of data. Input data are correct. 

Output

The result of the program is on the standard output. For each input data set the program prints on a single line “YES” if it is possible to form a committee and “NO” otherwise. There should not be any leading blanks at the start of the line.

Sample Input

2
3 3
3 1 2 3
2 1 2
1 1
3 3
2 1 3
2 1 3
1 1

Sample Output

YES
NO

Source

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/116823.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • CTFHUB——反射型XSS详解「建议收藏」

    CTFHUB——反射型XSS详解「建议收藏」背景本来看ctfhub上有xss的题目,打算好好学习一波,结果点开一看,只有一道题2333。便现在dvwa上熟悉了一波。所谓反射型是相对于存储型来讲的。如果黑客的xss注入是通过某种方式储存到了数据库中,那就是存储型的,这种xss的特点就是每次访问该页面都会收到xss攻击,因为js语句已经放在数据库里了。而反射型xss则不是这样,每次触发只能手动输入和点击才能触发。我认为xss产生的原因主要是对便签审查不严格造成的。dvwaxss例题下面写一下dvwa中的三种难度的反射型xss。<?

    2022年5月9日
    59
  • 从0开始学python_python37从零开始学

    从0开始学python_python37从零开始学如何用python进行期货程序化交易、程序化交易系统目前主要是通过计算机程序实现的,其实就是把交易者决策的过程用计算机语言描述出来,然后由计算机给出交易建议或直接发送交易指令到期货公司的。SDYGDFHFGJFGFTYKGHKTY你就是想找个软件或者券商的接口去上传交易指令,你前期的数据抓取和分析可能python都写好了,所以差这交易指令接口最后一步。对于股票的散户,正规的法子是华宝。国内量化交易…

    2022年10月8日
    3
  • malloc函数java_malloc函数详解及用法举例[通俗易懂]

    malloc函数java_malloc函数详解及用法举例[通俗易懂]malloc动态内存分配函数原理详解及编程用法举例(本文由www.169it.com搜集整理)malloc函数函数原型定义void*malloc(size_tsize);malloc函数原型说明malloc函数向系统申请分配size个字节的内存空间。返回值类型是void*类型。void*表示未确定类型的指针。c,c++规定,void*类型可以强制转换为任何其它类型的指针。malloc动…

    2022年5月5日
    131
  • Intellij Idea 主题下载(Eclectide Monokai)

    Intellij Idea 主题下载(Eclectide Monokai)从国外大神的博客上找的一个很棒的主题EclectideMonoka,感觉是在Durcula上做了很多优化,是黑色主题的升级版,通过一周的使用感觉非常爽,对方法、变量的高亮以及选中的显示等等色彩搭配挺好,分享一下

    2022年5月31日
    132
  • 调用接口返回中文乱码_java请求接口返回乱码

    调用接口返回中文乱码_java请求接口返回乱码最近调用Webservice接口时,遇到接收乱码的问题最开始用soapUI测试看XML结果是正常的,返回结果大概是这样(只截取了json部分结果){“state”:0,”message”:”流程启动成功”,”seqno”:”202005020009″}后来在JAVA后台使用HttpURLConnection调用(全部代码在后面),发现返回来的中文部分全部乱码,如下{“state…

    2022年8月31日
    4
  • js 符号转换 html代码

    js 符号转换 html代码S转换HTML转义符//去掉html标签//普通字符转换成转意符//转意符换成普通字符//转成空格//回车转为br标签//去除开头结尾换行,并将连续3次以上换行转换成2次换行//将多

    2022年7月1日
    25

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号