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. poj 3683 2-sat问题,输出任意一组可行解

    /* 2sat问题 输出任意一组可行解 */ #include<stdio.h> #include<string.h> #include<stdlib.h> #in ...

  2. javascript 保护变量不被随意修改------优雅的编程

    /* * 1.如果在renderTitle,renderContent里面,这样总数据谁都能修改,不安全 * 改进 * 1.规定一个专门修改数据的方法,如果想修改数据只能走这个方法 * * actio ...

  3. 积累js里有用的函数库

    一.兼容地获取非行间样式(兼容火狐,ie,chrome) function getStyle(obj,name) { if(obj.currentStyle){ return obj.currentS ...

  4. ***js常用方法汇总(源自实际中的项目)

    Q: 400-819-0717转8888,取后四位分机号 A: 方法一: alert("abcdefg".slice(-4));方法二:var str= "abcdefg ...

  5. ACM-ICPC 2018 焦作赛区网络预赛 H、L

    https://nanti.jisuanke.com/t/31721 题意 n个位置 有几个限制相邻的三个怎么怎么样,直接从3开始 矩阵快速幂进行递推就可以了 #include <bits/st ...

  6. Permutations(排列问题,DFS回溯)

    Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the follow ...

  7. [Bzoj1022][SHOI2008]小约翰的游戏John(博弈论)

    1022: [SHOI2008]小约翰的游戏John Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 2976  Solved: 1894[Submit] ...

  8. Md5扩展攻击的原理和应用

    *本文原创作者:Guilty and Innocent,本文属FreeBuf原创奖励计划,未经许可禁止转载 做CTF题目的过程中遇到了md5扩展攻击,参考了几篇文章,感觉写的都有些小缺陷,再发一篇文章 ...

  9. 【APUE】vim常用命令

    转自:http://coolshell.cn/articles/5426.html 基本命令: i → Insert 模式,按 ESC 回到 Normal 模式. x → 删当前光标所在的一个字符. ...

  10. Centos 6.x 安装Nagios及WEB管理nagiosql实现windows及linux监控指南

    一.Nagios简介 Nagios是一款开源的电脑系统和网络监视工具,能有效监控Windows.Linux和Unix的主机状态,交换机路由器等网络设置,打印机等.在系统或服务状态异常时发出邮件或短信报 ...