Tap here to switch tabs
Problem
Submissions

Problem: Count the Number of Inversions

med
30 min
Try to solve the Count the Number of Inversions problem.

Statement

You are given an integer n and a 2extD2 ext{D} integer array requirements, where requirements[i] = [end_i, cnt_i] denotes that the prefix of a permutation ending at index end_i must have exactly cnt_i inversions.

An inversion in an array nums is a pair of indices (i, j) such that i << j and nums[i] >> nums[j].

Return the number of permutations of the integers from 00 to n −1- 1 that satisfy all the given conditions. Since the result can be large, return it modulo 109+710^9 + 7.

Constraints:

  • 2≤2 \leq n ≤300\leq 300

  • 1≤1 \leq requirements.length ≤\leq n

  • requirements[i] = [end_i, cnt_i]

  • 0≤0 \leq end_i ≤\leq n −1- 1

  • 0≤0 \leq cnt_i ≤400\leq 400

  • The input is generated such that there is at least one index i satisfying end_i $= $ n −1- 1.

  • The input is generated such that all end_i values are unique.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Count the Number of Inversions

med
30 min
Try to solve the Count the Number of Inversions problem.

Statement

You are given an integer n and a 2extD2 ext{D} integer array requirements, where requirements[i] = [end_i, cnt_i] denotes that the prefix of a permutation ending at index end_i must have exactly cnt_i inversions.

An inversion in an array nums is a pair of indices (i, j) such that i << j and nums[i] >> nums[j].

Return the number of permutations of the integers from 00 to n −1- 1 that satisfy all the given conditions. Since the result can be large, return it modulo 109+710^9 + 7.

Constraints:

  • 2≤2 \leq n ≤300\leq 300

  • 1≤1 \leq requirements.length ≤\leq n

  • requirements[i] = [end_i, cnt_i]

  • 0≤0 \leq end_i ≤\leq n −1- 1

  • 0≤0 \leq cnt_i ≤400\leq 400

  • The input is generated such that there is at least one index i satisfying end_i $= $ n −1- 1.

  • The input is generated such that all end_i values are unique.