Skip to content

Commit

Permalink
Create code.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
wisdompeak authored Apr 2, 2021
1 parent ce68648 commit 1eb1688
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions LCCUP/2020Fall/LCP25.古董键盘/code.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
class Solution {
long dp[131][27];
public:
int keyboard(int k, int n)
{
long comb[131][131];
long M = 1e9+7;

for (int j=0; j<=26; j++)
dp[0][j] = 1;

for (int i = 0; i <= n; ++i)
{
comb[i][i] = comb[i][0] = 1;
if (i==0) continue;
for (int j = 1; j <= min(n, k); ++j)
{
comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
comb[i][j] %= M;
}
}

for (int i=1; i<=n; i++)
for (int j=1; j<=26; j++)
{
for (int t = 0; t <= min(i, k); t++)
{
dp[i][j] += dp[i-t][j-1] * comb[i][t];
dp[i][j] %= M;
}
}
return dp[n][26];
}
};

0 comments on commit 1eb1688

Please sign in to comment.