Tap here to switch tabs
Problem
Submissions

Problem: Count The Number of Winning Sequences

Count The Number of Winning Sequences asks you to count Bob's move sequences against Alice's string, with no consecutive repeats and a positive final score. Return the count modulo a large prime.

Statement

Alice and Bob are playing a game consisting of nn rounds. You are given a string s of length nn, where each character s[i] represents the creature Alice summons in the ithi^{ {th}} round:

  • 'F' represents a Fire Dragon

  • 'W' represents a Water Serpent

  • 'E' represents an Earth Golem

In each round, Bob also summons one of these three creatures. The outcome of each round is determined as follows:

  • Fire Dragon beats Earth Golem ('F' beats 'E').

  • Water Serpent beats Fire Dragon ('W' beats 'F').

  • Earth Golem beats Water Serpent ('E' beats 'W').

In every round:

  • If Bob summons a creature that beats Alice’s creature, Bob receives 11 point.

  • If Alice’s creature beats Bob’s creature, Bob loses 11 point.

  • If both summon the same creature, neither receives points (00 points).

Bob must follow a strict constraint: he cannot summon the same creature in two consecutive rounds.

Bob wins the game if his total points at the end of all nn rounds are strictly greater than 00.

Return the number of distinct winning move sequences Bob can make. Since the answer can be large, return it modulo 109+710^9 + 7.

Constraints:

  • 1≤1 \leq s.length ≤1000\leq 1000

  • s[i] is one of 'F', 'W', or 'E'.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Count The Number of Winning Sequences

Count The Number of Winning Sequences asks you to count Bob's move sequences against Alice's string, with no consecutive repeats and a positive final score. Return the count modulo a large prime.

Statement

Alice and Bob are playing a game consisting of nn rounds. You are given a string s of length nn, where each character s[i] represents the creature Alice summons in the ithi^{ {th}} round:

  • 'F' represents a Fire Dragon

  • 'W' represents a Water Serpent

  • 'E' represents an Earth Golem

In each round, Bob also summons one of these three creatures. The outcome of each round is determined as follows:

  • Fire Dragon beats Earth Golem ('F' beats 'E').

  • Water Serpent beats Fire Dragon ('W' beats 'F').

  • Earth Golem beats Water Serpent ('E' beats 'W').

In every round:

  • If Bob summons a creature that beats Alice’s creature, Bob receives 11 point.

  • If Alice’s creature beats Bob’s creature, Bob loses 11 point.

  • If both summon the same creature, neither receives points (00 points).

Bob must follow a strict constraint: he cannot summon the same creature in two consecutive rounds.

Bob wins the game if his total points at the end of all nn rounds are strictly greater than 00.

Return the number of distinct winning move sequences Bob can make. Since the answer can be large, return it modulo 109+710^9 + 7.

Constraints:

  • 1≤1 \leq s.length ≤1000\leq 1000

  • s[i] is one of 'F', 'W', or 'E'.