A14201 | Phoenix and Computers
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
There are $n$ 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-1$ and computer $i+1$ are both on, computer $i$ $(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 $M$ .
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 $M$ .
输入格式
The first line contains two integers $n$ and $M$ ( $3 \le n \le 400$ ; $10^8 \le M \le 10^9$ ) — the number of computers and the modulo. It is guaranteed that $M$ is prime.
输出格式
Print one integer — the number of ways to turn on the computers modulo $M$ .
输入输出样例
输入 #1
3 100000007
输出 #1
6
输入 #2
4 100000007
输出 #2
20
输入 #3
400 234567899
输出 #3
20914007
In the first example, these are the $6$ orders in which Phoenix can turn on all computers:
- $[1,3]$ . Turn on computer $1$ , then $3$ . Note that computer $2$ turns on automatically after computer $3$ is turned on manually, but we only consider the sequence of computers that are turned on manually.
- $[3,1]$ . Turn on computer $3$ , then $1$ .
- $[1,2,3]$ . Turn on computer $1$ , $2$ , then $3$ .
- $[2,1,3]$
- $[2,3,1]$
- $[3,2,1]$
- $[1,3]$ . Turn on computer $1$ , then $3$ . Note that computer $2$ turns on automatically after computer $3$ is turned on manually, but we only consider the sequence of computers that are turned on manually.
- $[3,1]$ . Turn on computer $3$ , then $1$ .
- $[1,2,3]$ . Turn on computer $1$ , $2$ , then $3$ .
- $[2,1,3]$
- $[2,3,1]$
- $[3,2,1]$
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted