zoukankan      html  css  js  c++  java
  • 【BZOJ】【1089】【SCOI2003】严格n元树

    高精度/递推


      Orz Hzwer……

      然而我想多了……

      理解以后感觉黄学长的递推好精妙啊

      顺便学到了一份高精度的板子= =233

      引用下题解:

    f[i]=f[i-1]^n+1

    ans=f[d]-f[d-1]

    然后加个高精度。。。

    话说这个数据范围是虚的吧。。。

    极限数据根本不会做。。

     1 /**************************************************************
     2     Problem: 1089
     3     User: Tunix
     4     Language: C++
     5     Result: Accepted
     6     Time:0 ms
     7     Memory:1352 kb
     8 ****************************************************************/
     9  
    10 //BZOJ 1089
    11 #include<cstdio>
    12 #include<cstring>
    13 #include<cstdlib>
    14 #include<iostream>
    15 #include<algorithm>
    16 #define rep(i,n) for(int i=0;i<n;++i)
    17 #define F(i,j,n) for(int i=j;i<=n;++i)
    18 #define D(i,j,n) for(int i=j;i>=n;--i)
    19 #define pb push_back
    20 using namespace std;
    21 typedef long long LL;
    22 inline int getint(){
    23     int r=1,v=0; char ch=getchar();
    24     for(;!isdigit(ch);ch=getchar()) if (ch=='-') r=-1;
    25     for(; isdigit(ch);ch=getchar()) v=v*10-'0'+ch;
    26     return r*v;
    27 }
    28 const int N=100010;
    29 /*******************template********************/
    30 struct bint{
    31     int l,v[1010];
    32     bint(){l=0;memset(v,0,sizeof v);}
    33     int& operator [] (int x){return v[x];}
    34 }f[20];
    35 const int Limit=10000;
    36 void print(bint a){
    37     printf("%d",a[a.l]);
    38     D(i,a.l-1,1) printf("%04d",a[i]);
    39     puts("");
    40 }
    41 bint operator * (bint a,bint b){
    42     bint c;
    43     F(i,1,a.l+b.l) c[i]=0;
    44     F(i,1,a.l) F(j,1,b.l)
    45         c[i+j-1]+=a[i]*b[j];
    46     c.l=a.l+b.l;
    47     F(i,1,c.l)
    48         if (c[i]>=Limit){
    49             if (i==c.l){
    50                 c.l++;
    51                 c[i+1]=c[i]/Limit;
    52             }else c[i+1]+=c[i]/Limit;
    53             c[i]%=Limit;
    54         }
    55     while(c.l>1 && !c[c.l]) c.l--;
    56     return c;
    57 }
    58 bint operator + (bint a,int p){
    59     a[1]+=p;
    60     int now=1;
    61     while(a[now]>=Limit){
    62         a[now+1]+=a[now]/Limit;
    63         a[now]%=Limit;
    64         now++;
    65         a.l=max(a.l,now);
    66     }
    67     return a;
    68 }
    69 bint operator - (bint a,bint b){
    70     F(i,1,a.l){
    71         a[i]-=b[i];
    72         if (a[i]<0){
    73             a[i]+=Limit;
    74             a[i+1]--;
    75         }
    76     }
    77     while(a.l>1 && !a[a.l]) a.l--;
    78     return a;
    79 }
    80 bint operator ^ (bint a,int b){
    81     bint r; r[r.l=1]=1;
    82     for(;b;b>>=1,a=a*a)
    83         if (b&1) r=r*a;
    84     return r;
    85 }
    86 int main(){
    87 #ifndef ONLINE_JUDGE
    88     freopen("1089.in","r",stdin);
    89     freopen("1089.out","w",stdout);
    90 #endif
    91     int n=getint(),d=getint();
    92     f[0][f[0].l=1]=1;
    93     F(i,1,d) f[i]=(f[i-1]^n)+1;
    94     print(f[d]-f[d-1]);
    95     return 0;
    96 }
    View Code

    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

    【样例输入1】
    2 2

    【样例输入2】
    2 3

    【样例输入3】
    3 5

    Sample Output

    【样例输出1】
    3

    【样例输出2】
    21

    【样例输出2】
    58871587162270592645034001

    HINT

    Source

    [Submit][Status][Discuss]
  • 相关阅读:
    nginx 超时配置、根据域名、端口、链接 配置不同跳转
    nginx 作用,初认识
    JVM理解
    使用开发IDE生成一个springboot工程。
    到spring官网创建第一个springboot工程
    linux 忘记root密码怎么处理。
    学习重新开始
    共同父域下的单点登录
    Bootstrap 与 Jquery validate 结合使用——多个规则实现
    Bootstrap 与 Jquery validate 结合使用——简单实现
  • 原文地址:https://www.cnblogs.com/Tunix/p/4506786.html
Copyright © 2011-2022 走看看