bzoj 1089: [SCOI2003]严格n元树【dp+高精】
2024-09-04 13:27:37
设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;
}
最新文章
- ExtJs 进度条(轮询)
- IntelliJ Idea 集成svn 和使用
- 151008:javascript不明白的地方
- 学习mongo系列(六)limit(munber),skip(number)
- canvas写的一个刮奖效果
- 2287: 【POJ Challenge】消失之物
- Java的历史
- 反向Ajax,第2部分:WebSocket
- Cocos2d-x FlappyBird
- foxpro常用命令
- fetch的使用说明
- ArrayList 和 LinkedList 的实现与区别
- JavaScript中8个常见的陷阱
- A. 【UR #16】破坏发射台
- cucumber_java从入门到精通(5)使用maven创建cucumber_java项目
- java学习——类之YuanZhu
- 解题:ZJOI 2013 K大数查询
- 使用C#进行基于PI的开发
- HTML5语义化标签总结
- linux下汇编语言开发总结