#abc291d. D - Flip Cards
D - Flip Cards
Score : points
问题描述
设有 张卡片,编号从 到 ,在一条线上排列。对于每个 ,第 张卡片和第 张卡片相邻。第 张卡片正面写有数字 ,背面写有数字 。最初,所有卡片都是正面朝上。
考虑从这 张卡片中选择零张或多张进行翻转。在 种选择卡片翻转的方式中,找出满足以下条件的翻牌方式的数量(模 ):
- 当所选卡片被翻转后,每对相邻卡片的正面朝上的整数都不相同。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
cards, numbered through , are arranged in a line. For each , card and card are adjacent to each other. Card has written on its front, and written on its back. Initially, all cards are face up.
Consider flipping zero or more cards chosen from the cards. Among the ways to choose the cards to flip, find the number, modulo , of such ways that:
- when the chosen cards are flipped, for every pair of adjacent cards, the integers written on their face-up sides are different.
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer as an integer.
Sample Input 1
3
1 2
4 2
3 4
Sample Output 1
4
Let be the set of card numbers to flip.
For example, when is chosen, the integers written on their visible sides are , and , from card to card , so it satisfies the condition.
On the other hand, when is chosen, the integers written on their visible sides are , and , from card to card , where the integers on card and card are the same, violating the condition.
Four satisfy the conditions: , and .
Sample Input 2
4
1 5
2 6
3 7
4 8
Sample Output 2
16
Sample Input 3
8
877914575 602436426
861648772 623690081
476190629 262703497
971407775 628894325
822804784 450968417
161735902 822804784
161735902 822804784
822804784 161735902
Sample Output 3
48
update @ 2024/3/10 12:08:51