zoukankan      html  css  js  c++  java
  • 卡特兰数 BZOJ3907 网格 NOIP2003 栈

    卡特兰数

    卡特兰数2

    卡特兰数:主要是求排列组合问题

    1:括号化矩阵连乘,问多少种方案

    2:走方格,不能过对角线,问多少种方案

    3:凸边型,划分成三角形

    4:1到n的序列进栈,有多少种出栈方案

     

    NOIP2003 栈 

     1 //#pragma comment(linker, "/STACK:167772160")//手动扩栈~~~~hdu 用c++交
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cstdlib>
     5 #include <iostream>
     6 #include <queue>
     7 #include <stack>
     8 #include <cmath>
     9 #include <set>
    10 #include <algorithm>
    11 #include <vector>
    12 // #include<malloc.h>
    13 using namespace std;
    14 #define clc(a,b) memset(a,b,sizeof(a))
    15 #define LL long long
    16 const int inf = 0x3f3f3f3f;
    17 const double eps = 1e-5;
    18 // const double pi = acos(-1);
    19 const LL MOD = 1e8;
    20 const int N=1<<13;
    21 // const LL p = 1e9+7;
    22 // inline int r(){
    23 //     int x=0,f=1;char ch=getchar();
    24 //     while(ch>'9'||ch<'0'){if(ch=='-') f=-1;ch=getchar();}
    25 //     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    26 //     return x*f;
    27 // }
    28 
    29 int main() {
    30     int n;
    31     LL f[20]={0};
    32     scanf("%d",&n);
    33     f[0]=1;f[1]=1;
    34     for(int i=2;i<=n;i++)
    35        for(int j=0;j<i;j++)
    36           f[i]+=f[j]*f[i-j-1];
    37     printf("%I64d
    ",f[n]);
    38     return 0;
    39 }

    BZOJ3907 网格

    转载

     1 /**************************************************************
     2     Problem: 3907
     3     User: Tunix
     4     Language: C++
     5     Result: Accepted
     6     Time:84 ms
     7     Memory:944 kb
     8 ****************************************************************/
     9  
    10 #include<cstdio>
    11 #include<cstring>
    12  
    13 typedef long long LL;
    14  
    15 const int N=10001;
    16 const LL mod=100000000;
    17  
    18 int tot=0,x[N],p[N],v[N]={0};
    19 LL a[1000],b[1000];
    20  
    21 LL pow(LL x,int p) {
    22     LL t=1;for (;p;p>>=1,x*=x) if (p&1) t*=x;return t;
    23 }
    24  
    25 void mul(LL a[],LL y) {
    26     LL x=0,&l=a[0];
    27     for (int i=1;i<=l;i++) {
    28         a[i]=a[i]*y+x;
    29         x=a[i]/mod;
    30         a[i]%=mod;
    31     }
    32     while (x) a[++l]=x%mod,x/=mod;
    33 }
    34  
    35 void dec(LL a[],LL b[]) {
    36     LL &l=a[0];
    37     for (int i=1;i<=l;i++) {
    38         if (a[i]<b[i]) a[i+1]--,a[i]+=mod;
    39         a[i]-=b[i];
    40     }
    41     while (!a[l]) l--;
    42 }
    43  
    44 void getc(LL a[],int n,int m) {
    45     memset(x,0,sizeof x);
    46     for (int i=2;i<=n;i++) x[i]++;
    47     for (int i=2;i<=m;i++) x[i]--;
    48     for (int i=2;i<=n-m;i++) x[i]--;
    49     for (int i=n;i>=2;i--)
    50     if (!v[i]) mul(a,pow(i,x[i]));
    51     else x[v[i]]+=x[i],x[i/v[i]]+=x[i];
    52 }
    53  
    54 void print(LL a[]) {
    55     int l=a[0];
    56     printf("%lld",a[l]);
    57     for (int i=l-1;i>=1;i--) printf("%08lld",a[i]);
    58     printf("
    ");
    59 }
    60  
    61 int main() {
    62     int n,m;
    63     scanf("%d%d",&n,&m);
    64     for (int i=2;i<=n+m;i++) {
    65         if (!v[i]) p[++tot]=i;
    66         for (int j=1,k;j<=tot,(k=p[j]*i)<=n+m;j++) {
    67             v[k]=p[j];
    68             if (i%p[j]==0) break;
    69         }
    70     }
    71     a[0]=a[1]=b[0]=b[1]=1;
    72     getc(a,n+m,n);
    73     getc(b,n+m,n+1);
    74     dec(a,b);
    75     print(a);
    76     return 0;
    77 }
  • 相关阅读:
    各大IT公司的起名缘由
    [转]深入探究Windows系统中INF的秘密
    终于部分解决了.NET Drawing.Printing中自定义PaperSize的问题
    通过预处理器指令调整连接的数据库
    LQ1600KIII针式打印机的卷纸控制
    WM有约II(四):你明天有空吗?
    WM有约II(三):整合Outlook Mobile的约会信息
    WM有约II(五):区别对待不同的手机号码
    WM有约II(一):你在干嘛?
    WM有约II(二):持续改进
  • 原文地址:https://www.cnblogs.com/ITUPC/p/5528673.html
Copyright © 2011-2022 走看看