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

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
V
V2EX
WordPress大学
WordPress大学
U
Unit 42
I
InfoQ
A
About on SuperTechFans
宝玉的分享
宝玉的分享
J
Java Code Geeks
博客园 - 司徒正美
爱范儿
爱范儿
Engineering at Meta
Engineering at Meta
G
Google Developers Blog
人人都是产品经理
人人都是产品经理
小众软件
小众软件
Microsoft Security Blog
Microsoft Security Blog
L
LangChain Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Hugging Face - Blog
Hugging Face - Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
aimingoo的专栏
aimingoo的专栏
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Last Week in AI
Last Week in AI
腾讯CDC
Recent Announcements
Recent Announcements

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

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