这题其实很水啊,就是高精度写了我一会。。
这个考虑对d值进行DP
我们只要限定有d-1这个深度就可以推过去了。。
然后因为怕重复,所以我枚举了一下最左边的d-1深度
算了,不想写了。。看看暴力代码吧。。有注释的
#include<cstdio>
#include<cstdlib>
#include<cstring>
struct Int
{
int a[10000];//东西
int len;//位数
};
int n,d;
int f[20];
void dfs (int x)//我想得到深度为d的状况
{
if (x==1) {f[x]=1;return ;}
dfs(x-1);
f[x]=0;
for (int u=1;u<=n;u++)//枚举第一个d-1层的是哪一个儿子
{
int tt=1;
int sum=0;
for (int j=1;j<=x-2;j++)//x-2层总共有多少种状况
sum=sum+f[j];
for (int i=1;i<u;i++)//那么这些就都是x-2了
tt=tt*sum;
tt=tt*f[x-1];
sum=sum+f[x-1];
for (int i=u+1;i<=n;i++)
tt=tt*sum;
if (x==5)
{
printf("%d %d\n",tt,sum);
}
f[x]+=tt;
}
return ;
}
int main()
{
f[0]=0;
scanf("%d%d",&n,&d);d++;
dfs(d);
printf("%d",f[d]);
//printf(f[d]);
return 0;
}
然后这题要用高精度。。好久没写,于是写挫了QAQ
反正数据小,很多地方都没有优化
#include<cstdio>
#include<cstdlib>
#include<cstring>
struct Int
{
int a[10000];//东西
int len;//位数
void clear() {memset(a,0,sizeof(a));len=1;}
};
int n,d;
Int f[20];
int mymax (int x,int y){return x>y?x:y;}
void print (Int x)
{
for (int u=x.len;u>=1;u--)
printf("%d",x.a[u]);
printf("\n");
}
Int add (Int a,Int b)
{
Int c;c.clear();
int len=mymax(a.len,b.len);
//print(a);print(b);
//printf("%d\n",len);
for (int u=1;u<=len;u++)
{
c.a[u]+=a.a[u]+b.a[u];
c.a[u+1]+=c.a[u]/10;
c.a[u]%=10;
}
c.len=len;
while (c.a[c.len+1]>0)
{
c.len++;
c.a[c.len+1]+=(c.a[c.len]/10);
c.a[c.len]%=10;
}
while (c.a[c.len]==0) c.len--;
return c;
}
Int Mul (Int a,Int b)
{
Int c;c.clear();
for (int u=1;u<=a.len;u++)
for (int i=1;i<=b.len;i++)
c.a[u+i-1]=c.a[u+i-1]+a.a[u]*b.a[i];
c.len=0;
while (c.a[c.len+1]>0||c.len<=a.len+b.len+5)
{
c.len++;
c.a[c.len+1]=c.a[c.len+1]+(c.a[c.len]/10);
c.a[c.len]%=10;
}
while (c.a[c.len]==0) c.len--;
return c;
}
void dfs (int x)//我想得到深度为d的状况
{
if (x==1)
{
f[x].clear();
f[x].a[1]=1;
return ;
}
dfs(x-1);
f[x].clear();
for (int u=1;u<=n;u++)//枚举第一个d-1层的是哪一个儿子
{
Int tt;tt.clear();tt.a[1]=1;
Int sum;sum.clear();
for (int j=1;j<=x-2;j++)//x-2层总共有多少种状况
sum=add(sum,f[j]);
//sum=sum+f[j];
for (int i=1;i<u;i++)//那么这些就都是x-2了
tt=Mul(tt,sum);
//tt=tt*sum;
//tt=tt*f[x-1];
tt=Mul(tt,f[x-1]);
//sum=sum+f[x-1];
sum=add(sum,f[x-1]);
for (int i=u+1;i<=n;i++)
tt=Mul(tt,sum);
/*if (x==5)
{
print(tt);print(sum);
}*/
//tt=tt*sum;
f[x]=add(f[x],tt);
//f[x]+=tt;
}
//print(f[x]);
return ;
}
int main()
{
f[0].clear();
scanf("%d%d",&n,&d);d++;
dfs(d);
// printf("%d",f[d]);
print(f[d]);
return 0;
}