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. php基础 数组 遍历

    //参数默认值// function abc($a,$b,$c=0){// echo $a,$b,$c;// }// abc(1,3); //可变参数//function def(){// $arr= ...

  2. BZOJ4553 - [TJOI2016]序列

    Portal Description 给出一个\(n(n\leq10^5)\)个数的数列\(\{a_n\}\)和\(m(m\leq10^5)\)个形如\((x,y)\)的变化,表示\(a_x\)可以变 ...

  3. hdu 4539

    #include<stdio.h> #include<string.h> ]; int s]; int main() { int i,j,n,m; int ch; while( ...

  4. jQuery操作元素的class属性

    今天在做一个菜单折叠插件的时候需要根据页面的url改变其class属性.jQuery操作元素的属性是非常方便的,在此记录一下: 1.给元素添加class属性: addClass(class) (1)添 ...

  5. linux命令2——进程相关

    (1)ps  -ef :可以看到内核的线程.

  6. msp430项目编程14

    msp430中项目---电子测重系统 1.hx711工作原理 2.电路原理说明 3.代码(显示部分) 4.代码(功能实现) 5.项目总结 msp430项目编程 msp430入门学习

  7. Apache 文件根目录设置修改方法 (Document Root)

    最近在学习WordPress,使用appServ 在windows上搭建Php开发环境 在网上查找到的关于修改Apache服务器根目录的资料,对比学习,再此记录 在安装 Apache 时,系统会给定一 ...

  8. HDU3549 最大流 裸题

    EK算法 时间复杂度o(n*m*m)  因为有反向边每次bfs时间为 n*m 每次删一条边 最多m次 代码 #include<iostream> #include<string.h& ...

  9. 洛谷—— P1462 通往奥格瑞玛的道路

    https://www.luogu.org/problem/show?pid=1462 题目背景 在艾泽拉斯大陆上有一位名叫歪嘴哦的神奇术士,他是部落的中坚力量 有一天他醒来后发现自己居然到了联盟的主 ...

  10. Eclipse中Maven运行项目时在Console中无日志出现的问题解决

    这是由于工作空间损坏造成的,比如重装JDK后,或者重装Maven后这些问题.解决方法如下: 1.删除现有工作空间,重新选择一个新的. 2.重置Workspece. 3.可能是Maven版本太新导致的, ...