zoukankan      html  css  js  c++  java
  • GT and set

    GT and set

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 605    Accepted Submission(s): 211


    Problem Description
    You are given N sets.The ith set has Ai numbers.

    You should divide the sets into L parts.

    And each part should have at least one number in common.

    If there is at least one solution,print YES,otherwise print NO.
     
    Input
    In the first line there is the testcase T (T20)

    For each teatcase:

    In the first line there are two numbers N and L.

    In the next N lines,each line describe a set.

    The first number is Ai,and then there are Ai distict numbers stand for the elements int the set.

    The numbers in the set are all positive numbers and they're all not bigger than 300.

    1N301L51Ai101LN

    You'd better print the enter in the last line when you hack others.

    You'd better not print space in the last of each line when you hack others.
     
    Output
    For each test print YES or NO
     
    Sample Input
    2 2 1 1 1 1 2 3 2 3 1 2 3 3 4 5 6 3 2 5 6
     
    Sample Output
    NO YES
    Hint
    For the second test,there are three sets:{1,2,3},{4,5,6},{2,5,6} You are asked to divide into two parts. One possible solution is to put the second and the third sets into the same part,and put the first in the other part. The second part and the third part have same number 6. Another solution is to put the first and the third sets into the same part,and put the second in the other part.
    #include<bits/stdc++.h>
    
    using namespace std;
    typedef long long ll;
    const int maxn = 2e5 + 50;
    
    int T,n,l,vis[1008];
    vector<int>e[maxn];
    
    inline bool check(int cur){
        for(register int i=0;i<e[cur].size();++i){
            if(vis[e[cur][i]])return true;
        }
        return false;
    }
    
    inline bool solve(int cur,int part){
        if(cur>n)return true;
        if(check(cur))return solve(cur+1,part);
        if(part>=l)return false;
        for(register int i=0;i<e[cur].size();++i){
            vis[e[cur][i]]=1;
            if(solve(cur+1,part+1))return true;
            vis[e[cur][i]]=0;
        }
        return false;
    }
    
    int main() {
    #ifndef ONLINE_JUDGE
        freopen("1.txt", "r", stdin);
    #endif
        scanf("%d",&T);
        while(T--){
            scanf("%d%d",&n,&l);
            memset(vis,0,sizeof(vis));
            for(register int i=1;i<=n;++i)e[i].clear();
            for(register int i=1,size;i<=n;++i){
                scanf("%d",&size);
                for(register int j=1,x;j<=size;++j){
                    scanf("%d",&x);
                    e[i].emplace_back(x);
                }
            }
            printf("%s
    ",solve(1,0)?"YES":"NO");
        }
        return 0;
    }
  • 相关阅读:
    字符串 CSV解析 表格 逗号分隔值 通讯录 电话簿 MD
    Context Application 使用总结 MD
    RxJava RxPermissions 动态权限 简介 原理 案例 MD
    Luban 鲁班 图片压缩 MD
    FileProvider N 7.0 升级 安装APK 选择文件 拍照 临时权限 MD
    组件化 得到 DDComponent JIMU 模块 插件 MD
    gradlew 命令行 build 调试 构建错误 Manifest merger failed MD
    protobuf Protocol Buffers 简介 案例 MD
    ORM数据库框架 SQLite 常用数据库框架比较 MD
    [工具配置]requirejs 多页面,多入口js文件打包总结
  • 原文地址:https://www.cnblogs.com/czy-power/p/11488263.html
Copyright © 2011-2022 走看看