leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

commit fdda3bddaf44ad2808c1041045946c2fc419a6ec
parent 95ca9de2bd17dc376d68d4700b0fe103a78179c2
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Sun,  6 Aug 2023 15:48:53 +0200

Daily Problem

Diffstat:
AProblems/0920.cpp | 17+++++++++++++++++
MREADME.md | 1+
2 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/Problems/0920.cpp b/Problems/0920.cpp @@ -0,0 +1,17 @@ +class Solution { + static const int MOD = 1e9 + 7; + long dp[101][101] = {1, 0}; + +public: + int numMusicPlaylists(int n, int goal, int k) { + for (int i = 1; i <= goal; i++) { + for (int j = 1; j <= n; j++) { + dp[i][j] = (dp[i - 1][j - 1] * (n - (j - 1))) % MOD; + if (j > k) { + dp[i][j] = (dp[i][j] + (dp[i - 1][j] * (j - k)) % MOD) % MOD; + } + } + } + return (int)dp[goal][n]; + } +}; diff --git a/README.md b/README.md @@ -394,6 +394,7 @@ for solving problems. | 0912 | Medium | [Sort an Array](Problems/0912.cpp) | | 0915 | Medium | [Partition Array into Disjoint Intervals](Problems/0915.cpp) | | 0918 | Medium | [Maximum Sum Circular Subarray](Problems/0918.cpp) | +| 0920 | Hard | [Number of Music Playlists](Problems/0920.cpp) | | 0926 | Medium | [Flip String to Monotone Increasing](Problems/0926.cpp) | | 0931 | Medium | [Minimum Falling Path Sum](Problems/0931.cpp) | | 0933 | Easy | [Number of Recent Calls](Problems/0933.cpp) |