#P10528. Battle Tactics in Star Rail
Battle Tactics in Star Rail
Battle Tactics in Star Rail
In the game Honkai: Star Rail, your team of four characters takes turns to act. All the characters share a common pool of Skill Points initially equal to k, and the maximum number of Skill Points is 5.
In each turn, the active character may choose one of two actions:
- Normal Attack (N): Increases the total Skill Points by 1 if the current Skill Points is less than 5; if Skill Points are at the maximum, performing a Normal Attack does not increase them.
- Skill (S): Consumes 1 Skill Point. If there are no Skill Points available, the character is forced to perform a Normal Attack.
To master the game, Corycle has classified his characters into three action types:
- Type 1: Always performs a Normal Attack.
- Type 2: If at least 1 Skill Point is available, the character must use a Skill; otherwise, performs a Normal Attack.
- Type 3: Has no restrictions and can choose either action. (Note: a Skill can only be used if there is at least 1 Skill Point.)
The battle progresses in rounds using a fixed turn order: the 1st character, then the 2nd, the 3rd, the 4th, and then back to the 1st character, and so on. When a character performs a Normal Attack, the Skill Points increase by 1 if they are below the maximum of 5 (or remain 5 if already maxed out). When a character performs a Skill, it consumes 1 Skill Point.
You are given the total number of actions n and the initial Skill Points k, as well as the type of each of the four characters in the fixed order. Your task is to compute the number of different possible action sequences that can occur. Two sequences are considered different if in at least one turn the actions (Normal Attack or Skill) differ. Since the answer can be very large, output it modulo \(998244353\).
inputFormat
The input consists of two lines:
- The first line contains two integers n and k (n is the total number of actions and k is the initial number of Skill Points).
- The second line contains four integers, each being 1, 2, or 3, representing the action type of the 1st, 2nd, 3rd, and 4th characters respectively.
outputFormat
Output a single integer, the number of different possible action sequences modulo \(998244353\).
sample
1 0
1 2 3 3
1