CF1515E.Phoenix and Computers

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There are nn computers in a row, all originally off, and Phoenix wants to turn all of them on. He will manually turn on computers one at a time. At any point, if computer i−1i-1 and computer i+1i+1 are both on, computer ii (2≤i≤n−1)(2 \le i \le n-1) will turn on automatically if it is not already on. Note that Phoenix cannot manually turn on a computer that already turned on automatically.

If we only consider the sequence of computers that Phoenix turns on manually, how many ways can he turn on all the computers? Two sequences are distinct if either the set of computers turned on manually is distinct, or the order of computers turned on manually is distinct. Since this number may be large, please print it modulo MM.

一行中有 nn 台计算机,初始时全部关闭,Phoenix 希望将它们全部打开。他将一台一台地手动开启计算机。在任意时刻,若第 i−1i-1 台和第 i+1i+1 台计算机均处于开启状态,则第 ii 台计算机(其中 2≤i≤n−12 \le i \le n-1)会自动开启(前提是它尚未开启)。注意:Phoenix 不能手动开启已经自动开启的计算机。

如果仅考虑 Phoenix 手动开启计算机的顺序,那么他有多少种方式可以最终开启所有计算机?若两个序列所包含的手动开启的计算机集合不同,或手动开启的顺序不同,则认为这两个序列是不同的。由于答案可能很大,请输出其对 MM 取模的结果。

输入格式

The first line contains two integers nn and MM (3≤n≤4003 \le n \le 400; 108≤M≤10910^8 \le M \le 10^9) — the number of computers and the modulo. It is guaranteed that MM is prime.

第一行包含两个整数 nn 和 MM(3≤n≤4003 \le n \le 400;108≤M≤10910^8 \le M \le 10^9),分别表示计算机的数量和模数。保证 MM 是质数。

输出格式

Print one integer — the number of ways to turn on the computers modulo MM.

输出一个整数——开启计算机的方案数对 MM 取模的结果。

输入输出样例

  • 输入#1

    3 100000007

    输出#1

    6
  • 输入#2

    4 100000007

    输出#2

    20
  • 输入#3

    400 234567899

    输出#3

    20914007

说明/提示

In the first example, these are the 66 orders in which Phoenix can turn on all computers:

  • [1,3][1,3]. Turn on computer 11, then 33. Note that computer 22 turns on automatically after computer 33 is turned on manually, but we only consider the sequence of computers that are turned on manually.
  • [3,1][3,1]. Turn on computer 33, then 11.
  • [1,2,3][1,2,3]. Turn on computer 11, 22, then 33.
  • [2,1,3][2,1,3]
  • [2,3,1][2,3,1]
  • [3,2,1][3,2,1]

在第一个例子中,凤凰开启所有计算机的顺序共有 66 种:

  • [1,3][1,3]:先开启计算机 11,再开启计算机 33。注意,计算机 22 会在计算机 33 被手动开启后自动开启,但我们只考虑被手动开启的计算机的顺序。
  • [3,1][3,1]:先开启计算机 33,再开启计算机 11。
  • [1,2,3][1,2,3]:依次开启计算机 11、22、33。
  • [2,1,3][2,1,3]
  • [2,3,1][2,3,1]
  • [3,2,1][3,2,1]

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

首页