• POJ 1632 Vase collection


    /*
     * dfs搜索题目,很经典,自己没想出来。
     * 关键是用bitset来判定是否有最大k个完美匹配,用法
     * 很经典,直接用位操作来实现,看了很久才明白这个
     * 算法的原理.............菜就一个次,我已说了N次......
     */


    #include
    <iostream>
    #include
    <cstdio>
    #include
    <algorithm>
    #include
    <memory.h>
    #include
    <cmath>
    #include
    <set>
    #include
    <bitset>
    #include
    <vector>
    using namespace std;

    const int BORDER = (1<<20)-1;
    const int MAXSIZE = 37;
    const int MAXN = 250100;
    const int INF = 0x4ffffff;
    #define CLR(x,y) memset(x,y,sizeof(x))
    #define ADD(x) x=((x+1)&BORDER)
    #define IN(x) scanf("%d",&x)
    #define OUT(x) printf("%d\n",x)
    #define MIN(m,v) (m)<(v)?(m):(v)
    #define MAX(m,v) (m)>(v)?(m):(v)
    #define ABS(x) (x>0?x:-x)

    bitset
    <MAXSIZE> state[MAXSIZE];
    int n,cur_n;
    int init()
    {
    int i,j;
    for(i = 0; i < MAXSIZE; ++i)
    state[i].reset();
    return 0;
    }
    bool dfs(const int& match,const int& cur,const int& sel,
    bitset
    <MAXSIZE> mask)
    {
    if(mask.count() < match)
    return false;
    else if(sel == match)
    return true;
    else if(sel + 36 - cur < match)
    return false;

    return dfs(match,cur+1,sel,mask) ||
    dfs(match,cur
    +1,sel+1,mask&state[cur]);
    }
    int input()
    {
    int i,a,b;
    IN(n);
    for(i = 0; i < n; ++i)
    {
    scanf(
    "%d%d",&a,&b);
    state[a
    -1].set(b-1);
    }
    return 0;
    }
    int work()
    {
    int i,j;
    bitset
    <MAXSIZE> mask;
    mask.
    set();
    for(cur_n = 2; cur_n*cur_n <= n&& dfs(cur_n,0,0,mask); ++cur_n)
    ;
    OUT(cur_n
    -1);
    return 0;
    }
    int main()
    {
    int i,j,tt;
    IN(tt);
    while(tt--)
    {
    init();
    input();
    work();
    }
    return 0;
    }

  • 相关阅读:
    Docker安装及基本命令
    SpringBoot-获取YAML文件值
    SpringBoot-YAML语法
    Maven仓库
    第一次使用Maven
    初始Maven
    索引的基本使用与创建选择
    了解索引为什么能快速查找数据
    Mysql的执行顺序与优化分析
    Mysql常用的几种join连接方式
  • 原文地址:https://www.cnblogs.com/lvpengms/p/1705539.html
Copyright © 2020-2023  润新知