-
Notifications
You must be signed in to change notification settings - Fork 1
/
Distinctwords.cpp
48 lines (42 loc) · 932 Bytes
/
Distinctwords.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
43
44
45
46
47
48
#include<bits/stdc++.h>
using namespace std;
class Solution
{
public:
int kvowelwords(int N, int K) {
vector < vector<long long> dp(N + 1, vector < long long(K + 1, 0));
for (int i = 0; i <= N; i++)
{
for (int j = 0; j <= K; ++j)
{
if (i == 0)
{
dp[i][j] = 1;
}
else
{
dp[i][j] = (dp[i - 1][K] * 21) % 1000000007;
if (j > 0)
{
dp[i][j] = (dp[i][j] + dp[i - 1][j - 1] * 5 % 1000000007) % 1000000007;
}
}
}
}
return dp[N][K];
}
};
int main()
{
int t;
cin >> t;
while (t--)
{
int N;int K;
cin >>N>>K;
Solution ob;
int ans = ob.kvowelwords(N,K);
cout << ans << endl;
}
return 0;
}