Skip to content

Commit 1eb1688

Browse files
authored
Create code.cpp
1 parent ce68648 commit 1eb1688

File tree

1 file changed

+34
-0
lines changed
  • LCCUP/2020Fall/LCP25.古董键盘

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
class Solution {
2+
long dp[131][27];
3+
public:
4+
int keyboard(int k, int n)
5+
{
6+
long comb[131][131];
7+
long M = 1e9+7;
8+
9+
for (int j=0; j<=26; j++)
10+
dp[0][j] = 1;
11+
12+
for (int i = 0; i <= n; ++i)
13+
{
14+
comb[i][i] = comb[i][0] = 1;
15+
if (i==0) continue;
16+
for (int j = 1; j <= min(n, k); ++j)
17+
{
18+
comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
19+
comb[i][j] %= M;
20+
}
21+
}
22+
23+
for (int i=1; i<=n; i++)
24+
for (int j=1; j<=26; j++)
25+
{
26+
for (int t = 0; t <= min(i, k); t++)
27+
{
28+
dp[i][j] += dp[i-t][j-1] * comb[i][t];
29+
dp[i][j] %= M;
30+
}
31+
}
32+
return dp[n][26];
33+
}
34+
};

0 commit comments

Comments
 (0)