C - Courses - hdu 1083(模板)

來源:互聯網
上載者:User

標籤:

一共有N個學生跟P門課程,一個學生可以任意選一

門或多門課,問是否達成:

  1.每個學生選的都是不同的課(即不能有兩個學生選同一門課)

  2.每門課都有一個代表(即P門課都被成功選過)

輸入為:

P N(課程數跟學生數)

接著有P行,格式為Count studenti studenti+1 ……studentcount

(Count表示對課程1感興趣的學生數,接著有Count個學生)

如第一行2 1 2表示學生1跟學生2對課程1感興趣

輸出為:

若能滿足上面兩個要求這輸出”YES”,否則為”NO”

注意:是課程匹配的學生,學生沒課上沒事.....********************************************************************#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;

const int MAXN = 1005;
const int oo = 1e9;

bool G[MAXN][MAXN], used[MAXN];
int p[MAXN], N, M;///n門課,M個學生

bool Find(int u)
{
    for(int i=1; i<=M; i++)
    {
        if(G[u][i] && used[i] == false)
        {
            used[i] = true;
            if(p[i] == false || Find(p[i]))
            {
                p[i] = u;
                return true;
            }
        }
    }

    return false;
}

int main()
{
    int T;

    scanf("%d", &T);

    while(T--)
    {
        int i, v, Q;

        memset(G, 0, sizeof(G));
        memset(p, 0, sizeof(p));

        scanf("%d%d", &N, &M);

        for(i=1; i<=N; i++)
        {
            scanf("%d", &Q);

            while(Q--)
            {
                scanf("%d", &v);
                G[i][v] = true;
            }
        }

        for(i=1; i<=N; i++)
        {
            memset(used, false, sizeof(used));
            if( Find(i) == false )
                break;
        }

        if(i <= N)
            printf("NO\n");
        else
            printf("YES\n");
    }

    return 0; 

}

 

C - Courses - hdu 1083(模板)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.