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 ...
随机推荐
- 今天买了个pro,开始ios开发
今天买了个mac pro 开始ios开发啦,爽!
- jsp 路径问题和环境路径以及各种路径总结
首先确定问题: 浏览器发送请求后,服务器会返回一个响应,但是返回的网页中,会有各种路径问题,所以在此用jsp中的属性来解决.(只是记录问题,用了不专业的术语,请见谅.) 总结: 以路径 http:/ ...
- ES6 export,import报错
问题描述: 现有两个文件: profile.js const firstName = 'Michael'; const lastName = 'Jackson'; const year = 2018; ...
- python 基础篇 15 内置函数和匿名函数
------------------------>>>>>>>>>>>>>>>内置函数<<< ...
- 1034 Head of a Gang (30 分)(图的遍历or并查集)
dfs #include<bits/stdc++.h> using namespace std; ; int mp[N][N]; int weight[N]; int vis[N]; ma ...
- 九度OJ--Q1164
import java.util.Scanner; /* * 题目描述: * 任意输入两个9阶以下矩阵,要求判断第二个是否是第一个的旋转矩阵,如果是,输出旋转角度(0.90.180.270),如果不是 ...
- Win7系统下删除文件时出现“正在准备再循环”的解决方法
今天,笔者在备份文件的时候,将一个word文档从移动硬盘复制到桌面.经过一系列“复(meng)杂(bi)”的操作之后,笔者突然发现,文件无法删除了.当右键文件点击“删除”时,出现对话框显示“正在准备 ...
- npm 版本问题
STF之问题篇 https://yq.aliyun.com/articles/221602 装完成后输入stf doctor查看工具依赖是否正确,安装教程可以参考我之前写的,这里不再多说,直接说问题. ...
- 官方文档 恢复备份指南八 RMAN Backup Concepts
本章内容 Consistent and Inconsistent RMAN Backups Online Backups and Backup Mode Backup Sets Image Copie ...
- [译]如何撤销git仓库里的所有修改?
原文来源:https://stackoverflow.com/questions/29007821/git-checkout-all-the-files 问: 如何撤销我在我git仓库所做的所有修改? ...