CF1038F.Wrap Around

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a binary string ss.

Find the number of distinct cyclical binary strings of length nn which contain ss as a substring.

The cyclical string tt contains ss as a substring if there is some cyclical shift of string tt, such that ss is a substring of this cyclical shift of tt.

For example, the cyclical string "000111" contains substrings "001", "01110" and "10", but doesn't contain "0110" and "10110".

Two cyclical strings are called different if they differ from each other as strings. For example, two different strings, which differ from each other by a cyclical shift, are still considered different cyclical strings.

给你一个二进制字符串 ss。

求长度为 nn 的、互不相同的循环二进制字符串中,有多少个字符串包含 ss 作为其子串。

循环字符串 tt 包含 ss 作为子串,当且仅当存在 tt 的某个循环移位,使得 ss 是该循环移位后的字符串的一个子串。

例如,循环字符串 "000111" 包含子串 "001"、"01110" 和 "10",但不包含 "0110" 和 "10110"。

若两个循环字符串作为普通字符串彼此不同,则称它们是不同的循环字符串。例如,两个仅通过循环移位相互得到的不同字符串,仍被视为不同的循环字符串。

输入格式

The first line contains a single integer nn (1≤n≤401 \le n \le 40) — the length of the target string tt.

The next line contains the string ss (1≤∣s∣≤n1 \le |s| \le n) — the string which must be a substring of cyclical string tt. String ss contains only characters '0' and '1'.

第一行包含一个整数 nn(1≤n≤401 \le n \le 40)——目标字符串 tt 的长度。

下一行包含字符串 ss(1≤∣s∣≤n1 \le |s| \le n)——该字符串必须是循环字符串 tt 的子串。字符串 ss 仅包含字符 '0' 和 '1'。

输出格式

Print the only integer — the number of distinct cyclical binary strings tt, which contain ss as a substring.

输出唯一的整数——包含 ss 作为子串的不同循环二进制字符串 tt 的数量。

输入输出样例

  • 输入#1

    2
    0

    输出#1

    3
  • 输入#2

    4
    1010

    输出#2

    2
  • 输入#3

    20
    10101010101010

    输出#3

    962

说明/提示

In the first example, there are three cyclical strings, which contain "0" — "00", "01" and "10".

In the second example, there are only two such strings — "1010", "0101".

在第一个例子中,有三个包含“0”的循环字符串——“00”、“01”和“10”。

在第二个例子中,仅有两个这样的字符串——“1010”、“0101”。

输入解题思路,AI测评打分。不知道怎么写?

首页