-
Notifications
You must be signed in to change notification settings - Fork 481
/
0920.cpp
42 lines (40 loc) · 962 Bytes
/
0920.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <string>
#include <vector>
#include <queue>
using namespace std;
static int x = []() {std::ios::sync_with_stdio(false); cin.tie(0); return 0; }();
class Solution
{
public:
int numMusicPlaylists(int N, int L, int K)
{
long mem[N+1][L+1], mod = 1e9+7;
for (unsigned int i = K + 1; i <= N; ++i)
{
for (unsigned int j = i; j <= L; ++j)
{
if (i == j or i == K + 1)
{
mem[i][j] = factorial(i);
}
else
{
mem[i][j] = (mem[i-1][j-1]*i + mem[i][j-1]*(i - K))%mod;
}
}
}
return (int)mem[N][L];
}
private:
long factorial(int n)
{
return n > 1 ? factorial(n - 1)*n%(long)(1e9+7) : 1;
}
};
int main()
{
int N = 2, L = 3, K = 1;
cout << Solution().numMusicPlaylists(N, L, K);
return 0;
}