ARC108D - AB
You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 600 points
Problem Statement
Given are an integer N and four characters cAA, cAB, cBA, and cBB.
Here, it is guaranteed that each of those four characters is A
or B
.
Snuke has a string s, which is initially AB
.
Let ∣s∣ denote the length of s. Snuke can do the four kinds of operations below zero or more times in any order:
- Choose i such that 1≤i<∣s∣, si =
A
, si+1 =A
and insert cAA between the i-th and (i+1)-th characters of s. - Choose i such that 1≤i<∣s∣, si =
A
, si+1 =B
and insert cAB between the i-th and (i+1)-th characters of s. - Choose i such that 1≤i<∣s∣, si =
B
, si+1 =A
and insert cBA between the i-th and (i+1)-th characters of s. - Choose i such that 1≤i<∣s∣, si =
B
, si+1 =B
and insert cBB between the i-th and (i+1)-th characters of s.
Find the number, modulo (109+7), of strings that can be s when Snuke has done the operations so that the length of s becomes N.
Constraints
- 2≤N≤1000
- Each of cAA, cAB, cBA, and cBB is
A
orB
.
Input
Input is given from Standard Input in the following format:
N cAA cAB cBA cBB
Output
Print the number, modulo (109+7), of strings that can be s when Snuke has done the operations so that the length of s becomes N.
Sample Input 1
4 A B B A
Sample Output 1
2
- There are two strings that can be s when Snuke is done:
ABAB
andABBB
.
Sample Input 2
1000 B B B B
Sample Output 2
1
- There is just one string that can be s when Snuke is done.
军训训练赛1
- Status
- Done
- Rule
- IOI
- Problem
- 7
- Start at
- 2023-8-20 8:00
- End at
- 2023-8-20 11:00
- Duration
- 3 hour(s)
- Host
- Partic.
- 12