bzoj 1089 SCOI2003严格n元树 递推
挺好想的,就是一直没调过,我也不知道哪儿的错,对拍也拍了,因为数据范围小,都快手动对拍了也不知道
哪儿错了。。。。
我们定义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元树 递推的更多相关文章
- BZOJ 1089: [SCOI2003]严格n元树
1089: [SCOI2003]严格n元树 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 1591 Solved: 795[Submit][Statu ...
- bzoj 1089 [SCOI2003]严格n元树(DP+高精度)
1089: [SCOI2003]严格n元树 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 1250 Solved: 621[Submit][Statu ...
- BZOJ 1089 SCOI2003 严格n元树 动态规划+高精度
题目大意:定义一棵深度为d的严格n元树为根的深度为0,最深的节点深度为d,且每一个非叶节点都有恰好n个子节点的树 给定n和d,求深度为d的严格n元树一共同拥有多少种 此题的递推部分并不难 首先我们设深 ...
- bzoj 1089: [SCOI2003]严格n元树【dp+高精】
设f[i]为深度为i的n元树数目,s为f的前缀和 s[i]=s[i-1]^n+1,就是增加一个根,然后在下面挂n个子树,每个子树都有s[i-1]种 写个高精就行了,好久没写WA了好几次-- #incl ...
- [BZOJ1089][SCOI2003]严格n元树(递推+高精度)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1089 分析: 第一感觉可以用一个通式求出来,但是考虑一下很麻烦,不好搞的.很容易发现最 ...
- 【BZOJ】1089: [SCOI2003]严格n元树(递推+高精度/fft)
http://www.lydsy.com/JudgeOnline/problem.php?id=1089 题意:求深度为d的n元树数目.(0<n<=32, 0<=d<=16) ...
- 【noi 2.6_9280】&【bzoj 1089】严格n元树(DP+高精度+重载运算符)
题意:定义一棵树的所有非叶节点都恰好有n个儿子为严格n元树.问深度为d的严格n元树数目. 解法:f[i]表示深度为<=i的严格n元树数目.f[i]-f[i-1]表示深度为i的严格n元树数目.f[ ...
- BZOJ 1089 严格n元树 (递推+高精度)
题解:用a[i]表<=i时有几种树满足度数要求,那么这样就可以递归了,a[i]=a[i-1]^n+1.n个节点每个有a[i-1]种情况,那么将其相乘,最后加上1,因为深度为0也算一种.那么答案就 ...
- 1089: [SCOI2003]严格n元树
好久没更新了..于是节操掉尽python水过本来就水的题.. n,d=map(int, raw_input().split()) if d==0: print 1 else: f=[1] for i ...
随机推荐
- [转]Git,SVN的优缺点及适合的范围,开源项目?公司项目?
使用git不久,粗浅理解: 1)适用对象不同.Git适用于参与开源项目的开发者.他们由于水平高,更在乎的是效率而不是易用性.Svn则不同,它适合普通的公司开发团队.使用起来更加容易. 2)使用的场合不 ...
- 【题解搬运】PAT_A1020 树的遍历
题目 Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder an ...
- Zabbix_agentd 启动报错
C:\zabbix>c:\Zabbix\zabbix_agentd.exe -i -c c:\Zabbix\zabbix_agentd.conf zabbix_agentd.exe [1144] ...
- DOM操作相关案例 模态对话框,简易留言板,js模拟选择器hover,tab选项卡,购物车案例
1.模态框案例 需求: 打开网页时有一个普通的按钮,点击当前按钮显示一个背景图,中心并弹出一个弹出框,点击X的时候会关闭当前的模态框 代码如下: <!DOCTYPE html> <h ...
- Spring实战第八章学习笔记————使用Spring Web Flow
Spring实战第八章学习笔记----使用Spring Web Flow Spring Web Flow是一个Web框架,它适用于元素按规定流程运行的程序. 其实我们可以使用任何WEB框架写流程化的应 ...
- ASP.NET MVC5.0 OutputCache不起效果
按照官网文档(https://docs.microsoft.com/en-us/aspnet/mvc/overview/older-versions-1/controllers-and-routing ...
- 团队项目-第十次scrum 会议
时间:11.6 时长:20分钟 地点:主235教室走廊 工作情况 团队成员 已完成任务 待完成任务 解小锐 完成多种招聘方式的逻辑编写 陈鑫 实现游戏的存档功能 李金奇 添加多种招聘方式等功能 王辰昱 ...
- 关于react-redux中Provider、connect的解析
Provider 是什么 react-redux 提供的一个 React 组件 作用 把 store 提供给其子组件 //使用 redux 的 createStore 方法创建的一个 store co ...
- [转]Hexo博客添加访问统计 - 记录
引入不蒜子 <script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"> ...
- Servlet入门(2)
1.url_pattern匹配模式 2.servlet生命周期 3.servlet线程问题 一.url_pattern 1.定义: 当浏览器发起一个url请求后,该请求发送到servlet容器的时候, ...