zoukankan      html  css  js  c++  java
  • 位运算——pku2436患病的奶牛

    患病的奶牛N只,D种病毒,最多包含K种病毒,求包含最多有几头牛

    6 3 2
    0
    1 1
    1 2
    1 3
    2 2 1
    2 2 1
    看到D的范围比较小<=15,用011,表示患了第2,3钟病毒的奶牛a[i]
    在枚举K种病毒,如110  (用STL里的排列函数枚举)m
    如m|a[i]==m,说明a[i]包括在m里,add++
    记录最大值
    View Code
    #include<algorithm>
    #include
    <iostream>
    #include
    <string.h>
    #include
    <stdio.h>
    using namespace std;

    int a[1009];
    bool b[19];

    int main()
    {
    int n,d,k;
    while(scanf("%d%d%d",&n,&d,&k)!=EOF)
    {
    int i,t,j,temp;
    for(i=0;i<n;i++)
    {
    scanf(
    "%d",&t);

    a[i]
    =0;
    for(j=0;j<t;j++)
    {
    scanf(
    "%d",&temp);
    a[i]
    +=1<<(temp-1);
    }
    }
    memset(b,
    0,sizeof(b));

    for(i=0;i<k;i++)
    {
    b[d
    -1-i]=1;
    }

    int max=0;
    do
    {
    int add=0;
    int all=0;
    for(i=0;i<d;i++)
    {
    if(b[i])
    all
    +=1<<i;
    }

    for(i=0;i<n;i++)
    {
    if((all|a[i])==all)
    add
    ++;
    }

    if(add>max)
    max
    =add;
    }
    while(next_permutation(&b[0],&b[d]));

    printf(
    "%d\n",max);
    }
    }

      

  • 相关阅读:
    Jmeter断言设置
    jmeter设置自动启动时间
    jmeter用命令行运行jmx脚本
    jmeter多用户并发压力测试(导入文件)
    Fiddler导出接口抓包数据
    postman和postwoman
    UVa10561
    UVa11859
    Ferguson游戏
    UVa11916
  • 原文地址:https://www.cnblogs.com/huhuuu/p/2167983.html
Copyright © 2011-2022 走看看