【BZOJ】【1089】【SCOI2003】严格n元树
高精度/递推
Orz Hzwer……
然而我想多了……
理解以后感觉黄学长的递推好精妙啊
顺便学到了一份高精度的板子= =233
引用下题解:
f[i]=f[i-1]^n+1
ans=f[d]-f[d-1]
然后加个高精度。。。
话说这个数据范围是虚的吧。。。
极限数据根本不会做。。
/**************************************************************
Problem: 1089
User: Tunix
Language: C++
Result: Accepted
Time:0 ms
Memory:1352 kb
****************************************************************/ //BZOJ 1089
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;++i)
#define F(i,j,n) for(int i=j;i<=n;++i)
#define D(i,j,n) for(int i=j;i>=n;--i)
#define pb push_back
using namespace std;
typedef long long LL;
inline int getint(){
int r=,v=; char ch=getchar();
for(;!isdigit(ch);ch=getchar()) if (ch=='-') r=-;
for(; isdigit(ch);ch=getchar()) v=v*-''+ch;
return r*v;
}
const int N=;
/*******************template********************/
struct bint{
int l,v[];
bint(){l=;memset(v,,sizeof v);}
int& operator [] (int x){return v[x];}
}f[];
const int Limit=;
void print(bint a){
printf("%d",a[a.l]);
D(i,a.l-,) printf("%04d",a[i]);
puts("");
}
bint operator * (bint a,bint b){
bint c;
F(i,,a.l+b.l) c[i]=;
F(i,,a.l) F(j,,b.l)
c[i+j-]+=a[i]*b[j];
c.l=a.l+b.l;
F(i,,c.l)
if (c[i]>=Limit){
if (i==c.l){
c.l++;
c[i+]=c[i]/Limit;
}else c[i+]+=c[i]/Limit;
c[i]%=Limit;
}
while(c.l> && !c[c.l]) c.l--;
return c;
}
bint operator + (bint a,int p){
a[]+=p;
int now=;
while(a[now]>=Limit){
a[now+]+=a[now]/Limit;
a[now]%=Limit;
now++;
a.l=max(a.l,now);
}
return a;
}
bint operator - (bint a,bint b){
F(i,,a.l){
a[i]-=b[i];
if (a[i]<){
a[i]+=Limit;
a[i+]--;
}
}
while(a.l> && !a[a.l]) a.l--;
return a;
}
bint operator ^ (bint a,int b){
bint r; r[r.l=]=;
for(;b;b>>=,a=a*a)
if (b&) r=r*a;
return r;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("1089.in","r",stdin);
freopen("1089.out","w",stdout);
#endif
int n=getint(),d=getint();
f[][f[].l=]=;
F(i,,d) f[i]=(f[i-]^n)+;
print(f[d]-f[d-]);
return ;
}
1089: [SCOI2003]严格n元树
Time Limit: 1 Sec Memory Limit: 162 MB
Submit: 977 Solved: 500
[Submit][Status][Discuss]
Description
如果一棵树的所有非叶节点都恰好有n个儿子,那么我们称它为严格n元树。如果该树中最底层的节点深度为d(根的深度为0),那么我们称它为一棵深度为d的严格n元树。例如,深度为2的严格2元树有三个,如下图:

给出n, d,编程数出深度为d的n元树数目。
Input
仅包含两个整数n, d( 0 < n < = 32, 0 < = d < = 16)
Output
仅包含一个数,即深度为d的n元树的数目。
Sample Input
2 2
【样例输入2】
2 3
【样例输入3】
3 5
Sample Output
3
【样例输出2】
21
【样例输出2】
58871587162270592645034001
HINT
Source
【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元树 递推
挺好想的,就是一直没调过,我也不知道哪儿的错,对拍也拍了,因为数据范围小,都快手动对拍了也不知道 哪儿错了.... 我们定义w[i]代表深度<=i的严格n元树的个数 那么最后w[d]-w[d-1 ...
- bzoj 1089: [SCOI2003]严格n元树【dp+高精】
设f[i]为深度为i的n元树数目,s为f的前缀和 s[i]=s[i-1]^n+1,就是增加一个根,然后在下面挂n个子树,每个子树都有s[i-1]种 写个高精就行了,好久没写WA了好几次-- #incl ...
- 【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[ ...
- 1089: [SCOI2003]严格n元树
好久没更新了..于是节操掉尽python水过本来就水的题.. n,d=map(int, raw_input().split()) if d==0: print 1 else: f=[1] for i ...
- BZOJ1089: [SCOI2003]严格n元树
1089: [SCOI2003]严格n元树 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 762 Solved: 387[Submit][Status ...
- bzoj1089 [SCOI2003]严格n元树(dp+高精)
1089: [SCOI2003]严格n元树 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 1899 Solved: 954[Submit][Statu ...
随机推荐
- think组合查询AND和OR一起用
如下示例: $_where 和 $where组合查询 $_where之间用OR $where之间用AND 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ...
- thinkphp中导入和使用阿里云OSSsdk
照做绝对行,在ThinkPHP中,第三方库都放在ThinkPHP/Library/Vendor/路径下. 1.下载OSS PHP SDK:https://help.aliyun.com/documen ...
- react篇章-React State(状态)-组件都是真正隔离的
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title&g ...
- React Native之网页组件WebView的使用与通信
在实际开发中,我们通常会嵌入一些html页面,官方为我们提供了一个非常好用的网页组件WebView,通过这个组件我们可以通过传入一个url或者是传入一段html 一. WebView的基本属性方法介绍 ...
- 解问 lambda表达式
目录 1.0 何为Lambda 1.1 Lambda语法特征 1.2 Lambda实例 1.3 Lambda中的stream 1.4 Lambda 中的 stream 效率 1.0 何为Lambda ...
- 异常:The server committed a protocol violation
异常记录: Exception rethrown at [0]: 在 Wintop.Windows.FrmLogin.btnLogin_Click(Object sender, EventArgs e ...
- 216. 组合总和 III
216. 组合总和 III 题意 找出所有相加之和为 n 的 k 个数的组合.组合中只允许含有 1 - 9 的正整数,并且每种组合中不存在重复的数字. 说明: 所有数字都是正整数. 解集不能包含重复的 ...
- 安装gitlab管理自己的代码
安装gitlab的资料网上搜索很多,但发现很多都是比较老的资料了.我把我安装的过程记录一下,应该是最简单的过程了 1. 到 https://about.gitlab.com/downloads/ 下载 ...
- Sql server 存储过程基础语法
一.定义变量 --简单赋值 declare @a int print @a --使用select语句赋值 declare @user1 nvarchar() select @user1='张三' pr ...
- ZOJ 3626 Treasure Hunt I 树上DP
E - Treasure Hunt I Time Limit:2000MS Memory Limit:65536KB Description Akiba is a dangerous country ...