Misha and Dima are promising young scientists. They make incredible discoveries every day together with their colleagues in the Spilkovo innovative center. Now Misha and Dima are studying the properties of an amazing function F which is written as follows.
C++:
int F(int x, int n)
{
return (((x & ((1 << (n / 2)) - 1)) << ((n + 1) / 2)) | (x >> (n / 2)));
}
Pascal:
function F(x, n: integer): integer;
begin
F := (((x and ((1 shl (n div 2)) - 1)) shl ((n + 1) div 2)) or (x shr (n div 2)));
end;
The friends want to perform the following computational experiment.
  1. All integers from 0 to 2n − 1 are written.
  2. Each integer x is replaced by F(xn).
  3. Each integer obtained after step 2 is written as a binary string of length n (if the integer has less than n bits, some leading zeroes are added; if the integer has more than n bits, only last n bits are written).
  4. The result of the experiment is a binary string of minimum length, that contains all the strings obtained after step 3 as its substrings.
If you can perform this experiment, maybe you are able to work in Spilkovo too!

Input

The only line contains an integer n (1 ≤ n ≤ 20).

Output

Output the required binary string. If there are several optimal solutions, you may output any of them.

Sample

input output
1
10
Problem Author: Ilya Kuchumov

题意:给定N,那么对于长度为N的二进制串有2^N种(0,1,2....2^N-1),现在把这些串用二进制表示处理,不满N位的前面补0,现在希望找到最短的字符串S,使得这些二进制串全部是S的字串。

思路:首先题目有个翻转过程,但其实翻转之后这2^N个数依然是对应(0,1,2...2^N-1),因为他们翻转前两两不同(至少有一位不同),翻转的时候按同样的规则翻转,所以翻转后也两两不同,所以值域不变。 所以可以不考虑翻转过程了。然后考虑求S:

有个叫‘德布鲁因序列’的东西:和什么差不多也是包含了所有的字串,但是多一个有环的性质,其答案的长度是2^N;   和它的证明相似,但是这里的S无环,所以长度是2^N+N-1。 根据其性质,知道‘德布鲁因序列’的数量是阶乘级别的,说明我们暴力求S的话,需要回溯的次数不多,所以N<=20我暴力回溯求S问题不大。

这个‘德布鲁因序列’,我大概看了一下,有些复杂,日后再细看咯。参考:http://www.cocoachina.com/cms/wap.php?action=article&id=21098

事实证明,只花了100ms。。不过应该有更高效的方法。

#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=;
int vis[maxn],a[maxn],M,N;
bool dfs(int p,int num){
if(p==M+){
for(int i=;i<=M;i++) printf("%d",a[i]);
cout<<endl;
return true;
}
num&=((<<(N-))-); num<<=;
if(!vis[num]){
vis[num]=;
a[p]=;
if(dfs(p+,num)) return true;
vis[num]=;
}
if(!vis[num+]){
vis[num+]=;
a[p]=;
if(dfs(p+,num+)) return true;
vis[num+]=;
}
return false;
}
int main()
{
cin>>N; M=pow(,N)+N-;
vis[]=; dfs(N+,);
return ;
}

Ural2004: Scientists from Spilkovo(德布鲁因序列&思维)的更多相关文章

  1. 德布鲁因序列与indexing 1

    目录 写在前面 标记left-most 1与right-most 1 确定位置 德布鲁因序列(De Bruijn sequence) 德布鲁因序列的使用 德布鲁因序列的生成与索引表的构建 参考 博客: ...

  2. 神秘常量0x077CB531,德布莱英序列的恩赐

    本文发布于游戏程序员刘宇的个人博客, 转载请注明来源https://www.cnblogs.com/xiaohutu/p/10950011.html 某天我在优化游戏的算法,在将一个个关键数据结构优化 ...

  3. 牛客OI测试赛 C 序列 思维

    链接:https://www.nowcoder.com/acm/contest/181/C来源:牛客网 题目描述 小a有n个数,他想把他们划分为连续的权值相等的k段,但他不知道这是否可行. 每个数都必 ...

  4. Codeforces Round #594 (Div. 1) D2. The World Is Just a Programming Task (Hard Version) 括号序列 思维

    D2. The World Is Just a Programming Task (Hard Version) This is a harder version of the problem. In ...

  5. De Bruijn序列

    最近文章中经常出现及De Bruijin 这个关键字,网上搜索了一下,记录下来. De Bruijn序列 (德布鲁因序列) 问题:能否构造一个长度为2的n次方的二进制环状串,使得二进制环状串中总共2的 ...

  6. 高效的多维空间点索引算法 — Geohash 和 Google S2

    原文地址:https://www.jianshu.com/p/7332dcb978b2   引子 每天我们晚上加班回家,可能都会用到滴滴或者共享单车.打开 app 会看到如下的界面:     app ...

  7. 3D-camera结构光原理

    3D-camera结构光原理 目前主流的深度探测技术是结构光,TOF,和双目.具体的百度就有很详细的信息. 而结构光也有双目结构光和散斑结构光等,没错,Iphone X 的3D深度相机就用 散斑结构光 ...

  8. <..................> 哈佛大学哲学系 && 历史哲学笔记文献集

    哈佛大学哲学系课程表            (一)概况    (1)哈佛大学哲学系现有教师21人,其中访问教授7人,教师流动性较大,每年有一定的变化.以下为现任教师:Richard Moran(系主任 ...

  9. BZOJ5259/洛谷P4747: [Cerc2017]区间

    BZOJ5259/洛谷P4747: [Cerc2017]区间 2019.8.5 [HZOI]NOIP模拟测试13 C.优美序列 思维好题,然而当成NOIP模拟题↑真的好吗... 洛谷和BZOJ都有,就 ...

随机推荐

  1. 81. Spring Boot集成JSP疑问【从零开始学Spring Boot】

    [原创文章,转载请注明出处] 针对文章: ()Spring Boot 添加JSP支持[从零开始学Spring Boot] 有网友提了这么一些疑问: 1.Spring Boot使用jsp时,仍旧可以打成 ...

  2. 线性回归Linear regression

    线性回归算法 解决回归问题 思想简单,容易实现 是许多强大的非线性模型的基础 结果具有很好的可解释性 蕴含机器学习中的很多重要思想 基本思想:寻找一条直线,最大程度的“拟合”样本特征和样本输出标记之间 ...

  3. Linux基础之vi编辑器(二)

    vi 编辑器 man vim 一 打开文件,定义光标 vi +# test       打开文件,定位于#行.vi + test        打开test文件,定位于最后一行.vi +/patter ...

  4. bzoj4027 [HEOI2015]兔子与樱花 树上贪心

    [HEOI2015]兔子与樱花 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 1320  Solved: 762[Submit][Status][Di ...

  5. spring几种依赖注入方式以及ref-local/bean,factory-bean,factory-method区别联系

    平常的java开发中,程序员在某个类中需要依赖其它类的方法,则通常是new一个依赖类再调用类实例的方法,这种开发存在的问题是new的类实例不好统一管理,spring提出了依赖注入的思想,即依赖类不由程 ...

  6. 洛谷P3094 [USACO13DEC]假期计划Vacation Planning

    题目描述 有N(1 <= N <= 200)个农场,用1..N编号.航空公司计划在农场间建立航线.对于任意一条航线,选择农场1..K中的农场作为枢纽(1 <= K <= 100 ...

  7. bitset初始化问题

    在C++primer上面说,bitset可以用unsigned long来进行初始化,但是上面的例子只是采用了常数如0xffff,而在实际中,当在vs2010中,我采用unsigned long类型的 ...

  8. Codeforces Round #297 (Div. 2) D. Arthur and Walls [ 思维 + bfs ]

    传送门 D. Arthur and Walls time limit per test 2 seconds memory limit per test 512 megabytes input stan ...

  9. 使用mysql-connector-java.jar连接MySql时出现:Error while retrieving metadata for procedure columns: java.sql.SQLException: Parameter/Column name pattern can not be NULL or empty.

    错误如下: 程序实现的功能是调用一个存储过程,但是不认这个存储过程的参数. 原因是版本太高了,由于使用的是6.0.6版本的,改成5.1.38即可. POM配置如下: <!-- mysql-con ...

  10. RabbitMQ Hello World

    RabbitMQ Hello World rabbitmq operation: C:\Program Files\RabbitMQ Server\rabbitmq_server-3.7.2\sbin ...