-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add solutions to lc problem: No.1866 (#1981)
No.1866.Number of Ways to Rearrange Sticks With K Sticks Visible
- Loading branch information
Showing
3 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
solution/1800-1899/1866.Number of Ways to Rearrange Sticks With K Sticks Visible/Solution.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
function rearrangeSticks(n: number, k: number): number { | ||
const mod = 10 ** 9 + 7; | ||
const f: number[] = Array(n + 1).fill(0); | ||
f[0] = 1; | ||
for (let i = 1; i <= n; ++i) { | ||
for (let j = k; j; --j) { | ||
f[j] = (f[j] * (i - 1) + f[j - 1]) % mod; | ||
} | ||
f[0] = 0; | ||
} | ||
return f[k]; | ||
} |