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

推荐订阅源

IT之家
IT之家
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
大猫的无限游戏
大猫的无限游戏
美团技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园_首页
MyScale Blog
MyScale Blog
N
Netflix TechBlog - Medium
I
InfoQ
Jina AI
Jina AI
Martin Fowler
Martin Fowler
Recent Announcements
Recent Announcements
量子位
月光博客
月光博客
罗磊的独立博客
雷峰网
雷峰网
The Cloudflare Blog
V
V2EX
小众软件
小众软件
人人都是产品经理
人人都是产品经理
博客园 - Franky
T
Tailwind CSS Blog
有赞技术团队
有赞技术团队
S
SegmentFault 最新的问题

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

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;
}