3320. Count The Number of Winning Sequences Hard
1/**
2 * [3320] Count The Number of Winning Sequences
3 *
4 * Alice and Bob are playing a fantasy battle game consisting of n rounds where they summon one of three magical creatures each round: a Fire Dragon, a Water Serpent, or an Earth Golem. In each round, players simultaneously summon their creature and are awarded points as follows:
5 *
6 * If one player summons a Fire Dragon and the other summons an Earth Golem, the player who summoned the Fire Dragon is awarded a point.
7 * If one player summons a Water Serpent and the other summons a Fire Dragon, the player who summoned the Water Serpent is awarded a point.
8 * If one player summons an Earth Golem and the other summons a Water Serpent, the player who summoned the Earth Golem is awarded a point.
9 * If both players summon the same creature, no player is awarded a point.
10 *
11 * You are given a string s consisting of n characters 'F', 'W', and 'E', representing the sequence of creatures Alice will summon in each round:
12 *
13 * If s[i] == 'F', Alice summons a Fire Dragon.
14 * If s[i] == 'W', Alice summons a Water Serpent.
15 * If s[i] == 'E', Alice summons an Earth Golem.
16 *
17 * Bob’s sequence of moves is unknown, but it is guaranteed that Bob will never summon the same creature in two consecutive rounds. Bob beats Alice if the total number of points awarded to Bob after n rounds is strictly greater than the points awarded to Alice.
18 * Return the number of distinct sequences Bob can use to beat Alice.
19 * Since the answer may be very large, return it modulo 10^9 + 7.
20 *
21 * <strong class="example">Example 1:
22 * <div class="example-block">
23 * Input: <span class="example-io">s = "FFF"</span>
24 * Output: <span class="example-io">3</span>
25 * Explanation:
26 * Bob can beat Alice by making one of the following sequences of moves: "WFW", "FWF", or "WEW". Note that other winning sequences like "WWE" or "EWW" are invalid since Bob cannot make the same move twice in a row.
27 * </div>
28 * <strong class="example">Example 2:
29 * <div class="example-block">
30 * Input: <span class="example-io">s = "FWEFW"</span>
31 * Output: <span class="example-io">18</span>
32 * Explanation:
33 * <w>Bob can beat Alice by making one of the following sequences of moves: "FWFWF", "FWFWE", "FWEFE", "FWEWE", "FEFWF", "FEFWE", "FEFEW", "FEWFE", "WFEFE", "WFEWE", "WEFWF", "WEFWE", "WEFEF", "WEFEW", "WEWFW", "WEWFE", "EWFWE", or "EWEWE".</w>
34 * </div>
35 *
36 * Constraints:
37 *
38 * 1 <= s.length <= 1000
39 * s[i] is one of 'F', 'W', or 'E'.
40 *
41 */
42pub struct Solution {}
43
44// problem: https://leetcode.com/problems/count-the-number-of-winning-sequences/
45// discuss: https://leetcode.com/problems/count-the-number-of-winning-sequences/discuss/?currentPage=1&orderBy=most_votes&query=
46
47// submission codes start here
48
49impl Solution {
50 pub fn count_winning_sequences(s: String) -> i32 {
51 0
52 }
53}
54
55// submission codes end
56
57#[cfg(test)]
58mod tests {
59 use super::*;
60
61 #[test]
62 fn test_3320() {
63 }
64}
65
Back
© 2025 bowen.ge All Rights Reserved.