zoukankan      html  css  js  c++  java
  • bzoj3033

     欧拉路,这题好神啊QAQ

    显然选择的方案数有2^n种,因为每个点度数都为二所以肯定是一条欧拉路,

    第二问直接爆搜即可...

    ————然而我并没有想到————

    第一问我推出来了(别问我怎么推的,我说我是蒙的好么...)

    然而第二问,我想的是先枚举2^n种01串

    然后显然最前面n位是0000...,最后n位是1111....

    之后将所有0000,1000,1100,1110,1111....全部加访问标记

    然后从0000开始往后拼,找与当前串错一位中间n-1位全部相同的未访问的串中字典序最小的那个(其实只有两个QwQ~)

    然后随便乱搞......

    额好像这就是正解了,然而我并不知道这是欧拉路...果然我还是太弱了TAT……

    #include<iostream>
    #include<algorithm>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    const int Mx=1<<12;
    int m,tot,ans[Mx];
    bool vis[Mx];
    bool find(int x,int num)
    {
        if(vis[x]) return false;
        vis[x]=1; ans[num]=x>>(m-1);
        if(num==tot) return true;
        if(find((x<<1)&(tot-1),num+1)) return true;
        if(find((x<<1|1)&(tot-1),num+1)) return true;
        vis[x]=0; return false;
    }
    int main()
    {
        scanf("%d",&m); tot=1<<m; printf("%d ",tot);
        find(0,1);
        for(int i=1;i<=tot;i++) printf("%d",ans[i]);
        return 0;
    }
  • 相关阅读:
    超级楼梯
    hdu1040
    hdu2033(惭愧)
    hdu2032杨辉三角
    hdu1013Digital Roots
    hdu2031
    Linux信号(signal) 机制分析
    android init重启service(进程)
    [android] init进程 .rc文件中service、action的parsing
    oom_adj
  • 原文地址:https://www.cnblogs.com/xiaoxubi/p/6147838.html
Copyright © 2011-2022 走看看