Class Solution
java.lang.Object
g1401_1500.s1420_build_array_where_you_can_find_the_maximum_exactly_k_comparisons.Solution
1420 - Build Array Where You Can Find The Maximum Exactly K Comparisons.<p>Hard</p>
<p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<p><img src="https://assets.leetcode.com/uploads/2020/04/02/e.png" alt="" /></p>
<p>You should build the array arr which has the following properties:</p>
<ul>
<li><code>arr</code> has exactly <code>n</code> integers.</li>
<li><code>1 <= arr[i] <= m</code> where <code>(0 <= i < n)</code>.</li>
<li>After applying the mentioned algorithm to <code>arr</code>, the value <code>search_cost</code> is equal to <code>k</code>.</li>
</ul>
<p>Return <em>the number of ways</em> to build the array <code>arr</code> under the mentioned conditions. As the answer may grow large, the answer <strong>must be</strong> computed modulo <code>10<sup>9</sup> + 7</code>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> n = 2, m = 3, k = 1</p>
<p><strong>Output:</strong> 6</p>
<p><strong>Explanation:</strong> The possible arrays are [1, 1], [2, 1], [2, 2], [3, 1], [3, 2] [3, 3]</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> n = 5, m = 2, k = 3</p>
<p><strong>Output:</strong> 0</p>
<p><strong>Explanation:</strong> There are no possible arrays that satisify the mentioned conditions.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> n = 9, m = 1, k = 1</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Explanation:</strong> The only possible array is [1, 1, 1, 1, 1, 1, 1, 1, 1]</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= n <= 50</code></li>
<li><code>1 <= m <= 100</code></li>
<li><code>0 <= k <= n</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
numOfArrays
public int numOfArrays(int n, int m, int k)
-