0920.cpp (497B)
1 class Solution { 2 static const int MOD = 1e9 + 7; 3 long dp[101][101] = {1, 0}; 4 5 public: 6 int numMusicPlaylists(int n, int goal, int k) { 7 for (int i = 1; i <= goal; i++) { 8 for (int j = 1; j <= n; j++) { 9 dp[i][j] = (dp[i - 1][j - 1] * (n - (j - 1))) % MOD; 10 if (j > k) { 11 dp[i][j] = (dp[i][j] + (dp[i - 1][j] * (j - k)) % MOD) % MOD; 12 } 13 } 14 } 15 return (int)dp[goal][n]; 16 } 17 };