惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Visual Studio Blog
IT之家
IT之家
博客园 - 聂微东
The Cloudflare Blog
月光博客
月光博客
阮一峰的网络日志
阮一峰的网络日志
S
SegmentFault 最新的问题
Apple Machine Learning Research
Apple Machine Learning Research
酷 壳 – CoolShell
酷 壳 – CoolShell
爱范儿
爱范儿
H
Help Net Security
博客园 - 叶小钗
V
V2EX
WordPress大学
WordPress大学
J
Java Code Geeks
Hugging Face - Blog
Hugging Face - Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园_首页
C
Check Point Blog
B
Blog
D
DataBreaches.Net
美团技术团队
罗磊的独立博客

博客园 - 来自海边的一片云

Binary Tree Maximum Path Sum 解题注意 CodingTMD’s Reading List Word Ladder I ,II 解题思路 suduko及8皇后问题及相关问题的解题思路 leetcode Word Break II 解题思路 Search for a string in an infinite stream of input string. 内存管理 Permutations leetcode Clone Graph leetcode 开弓没有回头箭 combination sum leetcode Combinations leetcode 组合问题 word break leetcode LRU cache Leetcode 重新试着写blog SQL injection Fuzz testing XML库的解析效率 Init()
De Bruijn 序列生成
来自海边的一片云 · 2014-02-19 · via 博客园 - 来自海边的一片云
#include "stdafx.h"
#include <vector>
using namespace std;
static vector<char> alpha;

void seq_printer(unsigned int* a, unsigned int* a_end)
{
    for (unsigned int* i = a; i < a_end; ++i)
    {
        printf("%c", alpha[*i]);
    }
}
void debruijn(unsigned int t,
    unsigned int p,
    const unsigned int k,
    const unsigned int n,
    unsigned int* a)
{
    if (t > n) {
        // we want only necklaces, not pre-necklaces or Lyndon words
        if (n % p == 0) {
            seq_printer(a + 1, a + p + 1);
        }
    }
    else {
        a[t] = a[t - p];

        debruijn(t + 1, p, k, n, a);

        for (unsigned int j = a[t - p] + 1; j < k; ++j) {
            a[t] = j;
            debruijn(t + 1, t, k, n, a);
        }
    }
}

int _tmain(int argc, _TCHAR* argv[])
{

    alpha.push_back('0');
    alpha.push_back('1');
    //alpha.push_back('c');
    int N = 3;
    unsigned int* a = new unsigned int[N + 1];
    a[0] = 0;

    debruijn(1, 1, alpha.size(), N,a);
    if (N > 0) printf("%c", alpha[0]);

    delete[] a;
}