Problem: with a [I] Table <= I when there are several trees to meet the degree requirements, then you can recursion, a [I] = A [I-1] ^ n + 1. N nodes each have a [I-1], then multiply it, and then add 1, because the depth is 0 is also considered. The answer is a [n]-A [n-1]. Then there is the problem of high precision. I found that the Code has not been detected for a long time and the high precision has not been felt. Even there are some problems with the high-Progress addition. Please pay special attention to it.
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;struct data{int len,a[2002];}a[35],c,p,t;int n,d;data mul(data a,data b){ memset(c.a,0,sizeof c.a); for(int i=1;i<=a.len;i++) for(int j=1;j<=b.len;j++){ c.a[i+j-1]+=a.a[i]*b.a[j]; c.a[i+j]+=c.a[i+j-1]/10000; c.a[i+j-1]%=10000; }c.len=2000; while(c.len&&!c.a[c.len])c.len--; return c;}data sum(data a,data b){ memset(c.a,0,sizeof c.a); c.len=max(a.len,b.len); for(int i=1;i<=c.len;i++){ c.a[i]+=a.a[i]+b.a[i]; c.a[i+1]+=c.a[i]/10000; c.a[i]%=10000; }c.len=2000; while(c.len&&!c.a[c.len])c.len--; return c;}data sub(data a,data b){ memset(c.a,0,sizeof c.a); c.len=a.len; for(int i=1;i<=a.len;i++){ c.a[i]=a.a[i]-b.a[i]; if(c.a[i]<0)c.a[i]+=10000,a.a[i+1]--; }while(c.len&&!c.a[c.len])c.len--; return c;}data power(data a,int b){ memset(p.a,0,sizeof p.a); p.len=1; p.a[1]=1; while(b){ if(b&1)p=mul(p,a); b>>=1; a=mul(a,a); }return p;}data op(data a,int b){ t.len=1; t.a[1]=1; return sum(power(a,b),t);}int main(){ scanf("%d%d",&n,&d); if(!d)return puts("1"),0; a[0].len=1; a[0].a[1]=1; for(int i=1;i<=d;i++)a[i]=op(a[i-1],n); a[d]=sub(a[d],a[d-1]); printf("%d",a[d].a[a[d].len]); for(int i=a[d].len-1;i;i--)printf("%04d",a[d].a[i]); return 0;}