• HDU 3006 The Number of set


    The Number of set

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 722    Accepted Submission(s): 437


    Problem Description
    Given you n sets.All positive integers in sets are not less than 1 and not greater than m.If use these sets to combinate the new set,how many different new set you can get.The given sets can not be broken.
     
    Input
    There are several cases.For each case,the first line contains two positive integer n and m(1<=n<=100,1<=m<=14).Then the following n lines describe the n sets.These lines each contains k+1 positive integer,the first which is k,then k integers are given. The input is end by EOF.
     
    Output
    For each case,the output contain only one integer,the number of the different sets you get.
     
    Sample Input
    4 4 1 1 1 2 1 3 1 4 2 4 3 1 2 3 4 1 2 3 4
     
    Sample Output
    15 2
     
    Source
     
    Recommend
    gaojie

    //这题很神奇的算法、呵呵

    #include <iostream>
    #include <stdio.h>
    #include <string.h>
    #define Y 1<<15
    using namespace std;
    bool a[Y+1];
    int main()
    {
        int n,m,in;
        int i,k,t,tin;
        while(scanf("%d%d",&n,&m)!=EOF)
        {
            t=1<<(m+1);
            for(i=1;i<=t;i++)
              a[i]=0;
            for(i=1;i<=n;i++)
            {
               scanf("%d",&k);
               tin=0;
               while(k--)
               {
                 scanf("%d",&in);
                 tin+=1<<in;
               }
               a[tin]=1;
              for(k=1;k<=t;k++)
                if(a[k])
                 a[k|tin]=1;
            }
            k=0;
          for(i=1;i<=t;i++)
              if(a[i])
               k++;
          printf("%d\n",k);
        }
        return 0;
    }

  • 相关阅读:
    使用truffle测试部署合约
    nodejs promise深度解析
    pthread线程特定数据
    基于信号量与互斥锁实现的生产者和消费者
    Linux coredump 的打开和关闭
    Linux 双网卡配置两个IP同时只有一个会通的原因
    进程间通信-共享内存
    进程间通信-消息队列
    TCP/IP SIGPIPE信号
    Select模式和超时
  • 原文地址:https://www.cnblogs.com/372465774y/p/2590368.html
Copyright © 2020-2023  润新知