R1
Problem 1
Find number of sequences of length \(n\) such that \(a_i \in [1..m]\) and \(\max(a_i) = m\).
Solution
\[\sum_{1 \le k \le n}{(-1)^{k - 1} \binom{n}{k} m^{n - k}} = m^n - (m-1)^n$$
$$\sum_{1 \le k \le n}{\binom{n}{k}(m-1)^{n-k}}\]
Problem 2
Find the number of sequences of length \(n\) such that: 1. \(a_i \in S_i\) where \(S_i\) is a multiset with value \(1 \le v \le m\) appearing \(f_i(v)\) times. The sequence is considered different if the index is different. 2. \(\max(a_i) = k\)
Solution
Inclusion-Exclusion is difficult. We can consider calculating the complement. $\(\prod_{i=1}^n \left( \sum_{v=1}^{k} f_i(v) \right) - \prod_{i=1}^n \left( \sum_{v=1}^{k-1} f_i(v) \right)\)$