QOJ.ac

QOJ

时间限制: 2.0 s 内存限制: 256 MB 总分: 100 可 Hack ✓

#17752. 街頭魔術師

统计

在參觀農夫市集時,Busy Beaver 停下來觀看一位街頭魔術師的表演。魔術師展示了一排 $N$ 個盒子,裡面裝著 $M$ 位元的非負整數 $a_1, a_2, \dots, a_N$,其中對於所有 $1 \le i \le N$,皆滿足 $0 \le a_i < 2^M$。

魔術師透過一系列的「魔法交換」將這些盒子按非遞減順序排列。在一次魔法交換中,魔術師選擇一個索引 $i$ ($1 \le i < N$),使得 $a_i$ 和 $a_{i+1}$ 的二進位表示恰好差一個位元,並交換 $a_i$ 和 $a_{i+1}$。

觀看表演時,Busy Beaver 對這個戲法的極限感到好奇。在所有 $2^{MN}$ 種可能的初始數值序列 $a_1, a_2, \dots, a_N$ 中,有多少種序列可以透過魔法交換排序成非遞減順序?由於這個數字可能很大,Busy Beaver 只需要求出該數值對 $10^9 + 7$ 取模後的結果。

輸入格式

輸入的第一行包含兩個整數 $N$ 和 $M$ ($1 \le N, M \le 50$)。

輸出格式

輸出一個整數:可以透過魔法交換排序的序列數量,對 $10^9 + 7$ 取模。

子任務

本題共有五個子任務:

  • (10 分):$1 \le N, M \le 5$。
  • (20 分):$1 \le M \le 4$。
  • (10 分):$1 \le M \le 10$。
  • (10 分):$1 \le M \le 15$。
  • (50 分):無額外限制。

範例

範例 1

3 2
44

範例 2

50 1
898961331

範例 3

10 10
649370314

說明

在第一個範例中,一個可以透過魔法交換排序的序列是 $[a_1, a_2, a_3] = [3, 1, 2]$,過程如下:

  1. 選擇 $i = 1$。注意 $a_1 = 3$ 和 $a_2 = 1$ 的二進位表示恰好差一個位元,因此這是一個魔法交換。序列變為 $[1, 3, 2]$。
  2. 選擇 $i = 2$。注意 $a_2 = 3$ 和 $a_3 = 2$ 的二進位表示恰好差一個位元,因此這是一個魔法交換。序列變為 $[1, 2, 3]$,此時已為非遞減順序。

在總共 $2^{3 \cdot 2} = 64$ 種初始序列中,有 44 種可以透過魔法交換排序。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.