|
1 | 1 | # [3577.Count the Number of Computer Unlocking Permutations][title] |
2 | 2 |
|
3 | | -> [!WARNING|style:flat] |
4 | | -> This question is temporarily unanswered if you have good ideas. Welcome to [Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm) |
5 | | -
|
6 | 3 | ## Description |
| 4 | +You are given an array `complexity` of length `n`. |
| 5 | + |
| 6 | +There are `n` **locked** computers in a room with labels from 0 to `n - 1`, each with its own **unique** password. The password of the computer `i` has a `complexity complexity[i]`. |
| 7 | + |
| 8 | +The password for the computer labeled 0 is **already** decrypted and serves as the root. All other computers must be unlocked using it or another previously unlocked computer, following this information: |
| 9 | + |
| 10 | +- You can decrypt the password for the computer `i` using the password for computer `j`, where `j` is **any** integer less than `i` with a lower complexity. (i.e. `j < i` and `complexity[j] < complexity[i]`) |
| 11 | +- To decrypt the password for computer `i`, you must have already unlocked a computer `j` such that `j < i` and `complexity[j] < complexity[i]`. |
| 12 | + |
| 13 | +Find the number of permutations of `[0, 1, 2, ..., (n - 1)]` that represent a valid order in which the computers can be unlocked, starting from computer 0 as the only initially unlocked one. |
| 14 | + |
| 15 | +Since the answer may be large, return it **modulo** `10^9 + 7`. |
| 16 | + |
| 17 | +**Note** that the password for the computer **with label** 0 is decrypted, and not the computer with the first position in the permutation. |
7 | 18 |
|
8 | 19 | **Example 1:** |
9 | 20 |
|
10 | 21 | ``` |
11 | | -Input: a = "11", b = "1" |
12 | | -Output: "100" |
13 | | -``` |
| 22 | +Input: complexity = [1,2,3] |
14 | 23 |
|
15 | | -## 题意 |
16 | | -> ... |
| 24 | +Output: 2 |
17 | 25 |
|
18 | | -## 题解 |
| 26 | +Explanation: |
| 27 | +
|
| 28 | +The valid permutations are: |
| 29 | +
|
| 30 | +[0, 1, 2] |
| 31 | +Unlock computer 0 first with root password. |
| 32 | +Unlock computer 1 with password of computer 0 since complexity[0] < complexity[1]. |
| 33 | +Unlock computer 2 with password of computer 1 since complexity[1] < complexity[2]. |
| 34 | +[0, 2, 1] |
| 35 | +Unlock computer 0 first with root password. |
| 36 | +Unlock computer 2 with password of computer 0 since complexity[0] < complexity[2]. |
| 37 | +Unlock computer 1 with password of computer 0 since complexity[0] < complexity[1]. |
| 38 | +``` |
| 39 | + |
| 40 | +**Example 2:** |
19 | 41 |
|
20 | | -### 思路1 |
21 | | -> ... |
22 | | -Count the Number of Computer Unlocking Permutations |
23 | | -```go |
24 | 42 | ``` |
| 43 | +Input: complexity = [3,3,3,4,4,4] |
25 | 44 |
|
| 45 | +Output: 0 |
| 46 | +
|
| 47 | +Explanation: |
| 48 | +
|
| 49 | +There are no possible permutations which can unlock all computers. |
| 50 | +``` |
26 | 51 |
|
27 | 52 | ## 结语 |
28 | 53 |
|
|
0 commit comments