Last active
November 6, 2018 10:46
-
-
Save fpdjsns/be0f98d94ff503cc0cb8274128a34baa to your computer and use it in GitHub Desktop.
[leetcode][920] Number of Music Playlists : https://leetcode.com/problems/number-of-music-playlists/
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
class Solution { | |
public: | |
int numMusicPlaylists(int N, int L, int K) { | |
//dp[N][L] = 노래 N개로 L만큼 들는 경우의 수 | |
vector<vector<int>> dp(N+1, vector<int>(L+1,0)); | |
int mod = 1e9 + 7; | |
dp[0][0] = 1; | |
for(int i= 1;i<=N;i++){ | |
for(int j=1;j<=L;j++){ | |
dp[i][j] = ((long long int)dp[i-1][j-1] * (N - (i-1)) + (long long int)dp[i][j-1] * max(0, i-K)) % mod; | |
} | |
} | |
return dp[N][L]; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment