DP+高精度。表示一开始看错题。。。不能更逗
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int k,n;
char dp[200][20][200];
char sum[250];
void plu(int x0,int y0,int x1,int y1)
{
for(int i=0;i<190;i++)
{
dp[x0][y0][i]+=dp[x1][y1][i];
if(dp[x0][y0][i]>=10)
{
dp[x0][y0][i]%=10;
dp[x0][y0][i+1]++;
}
}
}
int main()
{
scanf("%d%d",&n,&k);
memset(dp,0,sizeof(dp));
for(int i=1;i<k;i++)
dp[n][i][0]=1;
for(int j=n-1;j>0;j--)
{
for(int i=0;i<k;i++)
{
for(int l=1;l<k;l++)
{
plu(j,i,j+1,l);
}
if(i!=0)plu(j,i,j+1,0);
}
}
memset(sum,0,sizeof(sum));
for(int i=0;i<k;i++)
{
for(int j=0;j<190;j++)
{
sum[j]+=dp[1][i][j];
if(sum[j]>=10)
{
sum[j]%=10;
sum[j+1]++;
}
}
}
int top=190;
while(sum[top]==0)top--;
while(top+1)
printf("%d",sum[top--]);
printf("\n");
return 0;
}