In this fantasy battle game, Alice and Bob face off in n rounds of magical creature summoning! Each round, they simultaneously choose one of three powerful creatures:
- ๐ฅ Fire Dragon ('F') - Burns Earth Golems to ash
- ๐ Water Serpent ('W') - Extinguishes Fire Dragons
- ๐ Earth Golem ('E') - Absorbs Water Serpents
The rock-paper-scissors style scoring works as follows:
- Fire Dragon beats Earth Golem (Fire burns Earth)
- Water Serpent beats Fire Dragon (Water extinguishes Fire)
- Earth Golem beats Water Serpent (Earth absorbs Water)
- Same creatures = No points for either player
You know Alice's complete strategy as a string s of length n, but Bob's moves are unknown. However, Bob has one constraint: he never summons the same creature twice in a row.
Goal: Count how many different sequences Bob can play to strictly beat Alice (score more points than her). Return the answer modulo 10^9 + 7.
Input & Output
Visualization
Time & Space Complexity
n rounds ร 3 creatures ร O(n) possible score differences, with memoization preventing recalculation
Memoization table storing results for all possible states
Constraints
- 1 โค s.length โค 1000
- s consists only of characters 'F', 'W', and 'E'
- Bob never summons the same creature in consecutive rounds
- Answer fits in 32-bit integer when taken modulo 109 + 7