挺好想的,就是一直没调过,我也不知道哪儿的错,对拍也拍了,因为数据范围小,都快手动对拍了也不知道

哪儿错了。。。。

我们定义w[i]代表深度<=i的严格n元树的个数

那么最后w[d]-w[d-1]就是答案

那么对于w[i],我们由w[i-1]递推来,

我们考虑新加一个根节点,然后根节点有n个子节点,每个子节点都可以建一颗深度<=i-1的树,那么每个

子节点都有w[i-1]种选法,那么n个子节点就有w[i-1]^n选法,再加上都不选,就是深度为0的情况

那么w[i]:=(w[i-1]^n)+1;

//By BLADEVIL
var
w :array[-..] of ansistring;
n, d :longint;
a, b, c :array[..] of int64; function mul(s1,s2:ansistring):ansistring;
var
i, j :longint;
len1, len2 :longint;
s :ansistring;
begin
len1:=length(s1);
len2:=length(s2);
fillchar(c,sizeof(c),);
fillchar(a,sizeof(a),);
fillchar(b,sizeof(b),);
for i:= to len1 do a[(len1-i) div +]:=a[(len1-i) div +]*+ord(s1[i])-;
for i:= to len2 do b[(len2-i) div +]:=b[(len2-i) div +]*+ord(s2[i])-;
len1:=(len1+) div ;
len2:=(len2+) div ;
for i:= to len1 do
for j:= to len2 do
begin
c[i+j-]:=c[i+j-]+a[i]*b[j];
c[i+j]:=c[i+j]+c[i+j-] div ;
c[i+j-]:=c[i+j-] mod ;
end;
mul:='';
len1:=len1+len2+;
for i:=len1 downto do
begin
if c[i]< then mul:=mul+'';
if c[i]< then mul:=mul+'';
if c[i]< then mul:=mul+'';
str(c[i],s);
mul:=mul+s;
end;
while (mul[]='') and (length(mul)>) do delete(mul,,);
end; function mi(x:ansistring):ansistring;
var
p :longint;
ans, sum :ansistring;
begin
ans:='';
sum:=x;
p:=n;
while p<> do
begin
if p mod = then ans:=mul(ans,sum);
p:=p div ;
sum:=mul(sum,sum);
end;
mi:=ans;
end; function inc(x:ansistring):ansistring;
var
len :longint;
i :longint;
s :ansistring; begin
len:=length(x);
for i:= to len do c[i]:=ord(x[i])-;
c[len]:=c[len]+;
for i:=len downto do
begin
c[i-]:=c[i-]+c[i] div ;
c[i]:=c[i] mod ;
end;
inc:='';
len:=len;
for i:= to len do
begin
str(c[i],s);
inc:=inc+s;
end;
while (inc[]='') and (length(inc)>) do delete(inc,,);
end; function jian(s1,s2:ansistring):ansistring;
var
i :longint;
len1, len2 :longint;
s :ansistring;
begin
len1:=length(s1);
len2:=length(s2);
fillchar(c,sizeof(c),);
for i:= to len1 do a[len1-i+]:=ord(s1[i])-;
for i:= to len2 do b[len2-i+]:=ord(s2[i])-;
for i:= to len1 do c[i]:=a[i]-b[i];
for i:= to len1 do
if c[i]< then
begin
c[i]:=c[i]+;
c[i+]:=c[i+]-;
end;
jian:='';
for i:=len1 downto do
begin
str(c[i],s);
jian:=jian+s;
end;
while (jian[]='') and (length(jian)>) do delete(jian,,);
end; procedure main;
var
i :longint;
begin
readln(n,d);
if d= then
begin
writeln();
exit;
end;
w[]:='';
for i:= to d do w[i]:=inc(mi(w[i-]));
writeln(jian(w[d],w[d-]));
end; begin
main;
end.

bzoj 1089 SCOI2003严格n元树 递推的更多相关文章

  1. BZOJ 1089: [SCOI2003]严格n元树

    1089: [SCOI2003]严格n元树 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 1591  Solved: 795[Submit][Statu ...

  2. bzoj 1089 [SCOI2003]严格n元树(DP+高精度)

    1089: [SCOI2003]严格n元树 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 1250  Solved: 621[Submit][Statu ...

  3. BZOJ 1089 SCOI2003 严格n元树 动态规划+高精度

    题目大意:定义一棵深度为d的严格n元树为根的深度为0,最深的节点深度为d,且每一个非叶节点都有恰好n个子节点的树 给定n和d,求深度为d的严格n元树一共同拥有多少种 此题的递推部分并不难 首先我们设深 ...

  4. bzoj 1089: [SCOI2003]严格n元树【dp+高精】

    设f[i]为深度为i的n元树数目,s为f的前缀和 s[i]=s[i-1]^n+1,就是增加一个根,然后在下面挂n个子树,每个子树都有s[i-1]种 写个高精就行了,好久没写WA了好几次-- #incl ...

  5. [BZOJ1089][SCOI2003]严格n元树(递推+高精度)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1089 分析: 第一感觉可以用一个通式求出来,但是考虑一下很麻烦,不好搞的.很容易发现最 ...

  6. 【BZOJ】1089: [SCOI2003]严格n元树(递推+高精度/fft)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1089 题意:求深度为d的n元树数目.(0<n<=32, 0<=d<=16) ...

  7. 【noi 2.6_9280】&【bzoj 1089】严格n元树(DP+高精度+重载运算符)

    题意:定义一棵树的所有非叶节点都恰好有n个儿子为严格n元树.问深度为d的严格n元树数目. 解法:f[i]表示深度为<=i的严格n元树数目.f[i]-f[i-1]表示深度为i的严格n元树数目.f[ ...

  8. BZOJ 1089 严格n元树 (递推+高精度)

    题解:用a[i]表<=i时有几种树满足度数要求,那么这样就可以递归了,a[i]=a[i-1]^n+1.n个节点每个有a[i-1]种情况,那么将其相乘,最后加上1,因为深度为0也算一种.那么答案就 ...

  9. 1089: [SCOI2003]严格n元树

    好久没更新了..于是节操掉尽python水过本来就水的题.. n,d=map(int, raw_input().split()) if d==0: print 1 else: f=[1] for i ...

随机推荐

  1. 【数据库】 SQLite 语法

    [数据库] SQLite 语法 一 . 创建数据库 1. 只需创建数据库,只需创建文件,操作时将连接字符串指向该文件即可 2. 连接字符串 : data source = FilePath; 不能加密 ...

  2. iOS-读写plist文件

    读写plist文件 问题,我有一个plist文件,表示56个民族的,但是里面保存的字典,我想转换成一个数组 好的,那么就先遍历这个plist,然后将结果保存到一个数组中,这里出现的一个问题就是C语言字 ...

  3. Viewer.js 图片预览插件使用

    一.简介 Viewer.js 是一款强大的图片查看器. Viewer.js 有以下特点: 支持移动设备触摸事件 支持响应式 支持放大/缩小 支持旋转(类似微博的图片旋转) 支持水平/垂直翻转 支持图片 ...

  4. 以太坊solidity编程常见错误(不定期更新)

    1.报错: Expected token Semicolon got 'eth_compileSolidity' funtion setFunder(uint _u,uint _amount){ 解决 ...

  5. Python 并发编程:PoolExecutor 篇

    个人笔记,如有疏漏,还请指正. 使用多线程(threading)和多进程(multiprocessing)完成常规的并发需求,在启动的时候 start.join 等步骤不能省,复杂的需要还要用 1-2 ...

  6. Pro Git - 笔记1

    Getting Started About Version Control Local Version Control Systems Centralized Version Control Syst ...

  7. DFS(6)——hdu1342Lotto

    一.题目回顾 题目链接:Lotto Sample Input 7 1 2 3 4 5 6 7 8 1 2 3 5 8 13 21 34 0 Sample Output 1 2 3 4 5 6 1 2 ...

  8. Java 无法初始化Connection的问题

    通过断点调试捕获错误消息:The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time ...

  9. servlet入门(1)

    第一个servlet类 1.编写一个java类,继承HttpServlet类 2.重写doget和dopost方法 3.Servlet程序在tomcat服务器运行 第一步:找到server窗口,并新建 ...

  10. lintcode-91-最小调整代价

    91-最小调整代价 给一个整数数组,调整每个数的大小,使得相邻的两个数的差不大于一个给定的整数target,调整每个数的代价为调整前后的差的绝对值,求调整代价之和最小是多少. 注意事项 你可以假设数组 ...