设f[i]为深度为i的n元树数目,s为f的前缀和

s[i]=s[i-1]^n+1,就是增加一个根,然后在下面挂n个子树,每个子树都有s[i-1]种

写个高精就行了,好久没写WA了好几次……

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=55,mod=1e8;
int n,m;
struct qwe
{
long long a[N];
void clr()
{
memset(a,0,sizeof(a));
}
qwe operator + (const qwe &b) const
{
qwe c;
c.clr();
for(int i=1;i<=50;i++)
{
c.a[i]+=a[i]+b.a[i];
c.a[i+1]+=c.a[i]/mod;
c.a[i]%=mod;
}
return c;
}
qwe operator -(const qwe &b) const
{
qwe c;
c.clr();
for(int i=1;i<=50;i++)
{
c.a[i]+=a[i]-b.a[i];
if(c.a[i]<0)
{
c.a[i]+=mod;
c.a[i+1]--;
}
}
return c;
}
qwe operator * (const qwe &b) const
{
qwe c;
c.clr();
for(int i=1;i<=50;i++)
for(int j=1;j+i-1<=50;j++)
c.a[j+i-1]+=a[i]*b.a[j];
for(int i=1;i<=50;i++)
{
c.a[i+1]+=c.a[i]/mod;
c.a[i]%=mod;
}
return c;
}
}s[N],y;
qwe ksm(qwe a,int b)
{
qwe r=y;
while(b)
{
if(b&1)
r=r*a;
a=a*a;
b>>=1;
}
return r;
}
int main()
{
scanf("%d%d",&n,&m);
if(m==0)
{
puts("1");
return 0;
}
y.a[1]=1;
s[0]=y;
for(int i=1;i<=m;i++)
s[i]=ksm(s[i-1],n)+y;
qwe ans=s[m]-s[m-1];
int l=50;
while(!ans.a[l])
l--;
printf("%lld",ans.a[l]);
for(int i=l-1;i>=1;i--)
printf("%08lld",ans.a[i]);
return 0;
}

最新文章

  1. ExtJs 进度条(轮询)
  2. IntelliJ Idea 集成svn 和使用
  3. 151008:javascript不明白的地方
  4. 学习mongo系列(六)limit(munber),skip(number)
  5. canvas写的一个刮奖效果
  6. 2287: 【POJ Challenge】消失之物
  7. Java的历史
  8. 反向Ajax,第2部分:WebSocket
  9. Cocos2d-x FlappyBird
  10. foxpro常用命令
  11. fetch的使用说明
  12. ArrayList 和 LinkedList 的实现与区别
  13. JavaScript中8个常见的陷阱
  14. A. 【UR #16】破坏发射台
  15. cucumber_java从入门到精通(5)使用maven创建cucumber_java项目
  16. java学习——类之YuanZhu
  17. 解题:ZJOI 2013 K大数查询
  18. 使用C#进行基于PI的开发
  19. HTML5语义化标签总结
  20. linux下汇编语言开发总结

热门文章

  1. ubuntu 14.04 安装docker,docker-compose
  2. Django学习之 - 基础部分
  3. Codechef May Challenge 2015
  4. 一个Tomcat最多支持多少用户的并发?
  5. JDBC调用存储过程,进参出参
  6. @Retention n. 保留
  7. Please enter a commit message to explain why this merge is necessary.
  8. MySQL基础笔记(三) 复杂查询
  9. iOS xmpp的使用
  10. 【转】Selenium2学习路线