Skip to content

Instantly share code, notes, and snippets.

@fpdjsns
Last active November 6, 2018 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fpdjsns/be0f98d94ff503cc0cb8274128a34baa to your computer and use it in GitHub Desktop.
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/
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