zoukankan      html  css  js  c++  java
  • UVA

    Description

    Download as PDF

    Problem A

    Expression Bracketing

    Input: standard input

    Output: standard output

    Time Limit: 1 second

    Memory Limit: 32 MB

    Inthis problem you will have to find in how many ways n letters can be bracketed so that the bracketing is non-binarybracketing. For example 4 lettershave 11 possible bracketing:

     

    xxxx, (xx)xx, x(xx)x, xx(xx),(xxx)x, x(xxx), ((xx)x)x, (x(xx))x, (xx)(xx), x((xx)x), x(x(xx)). Of these the first sixbracketing are not binary. Given the number of letters you will have to findthe total number of non-binary bracketing.

     

    Input

    Theinput file contains several lines of input. Each line contains a single integern (0<n<=26). Input isterminated by end of file.

     

    Output

    For each line of input produce one line of outputwhich denotes the number of non binary bracketing with n letters.

     

    Sample Input

    3

    4

    5

    10

    Sample Output

    1

    6

    31

    98187

    题意:假设p。q是要求的串,那么(p。q)也满足。求全部不可能的条件

    思路:我们先求满足的,能够想象的到,这个跟卡特兰数的思路是类似的,都是将串分成(1, n-1), (2, n-2)....考虑的,可是全部的情况可能就难求了。了解后是个叫

    Super Catalan Number    的序列,相减求结果,可是注意卡特兰数都从0開始的

    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <algorithm>
    typedef long long ll;
    using namespace std;
    const int maxn = 30;
    
    int n;
    ll catalan[maxn], supper[maxn];
    
    void init() {
    	supper[0] = supper[1] = supper[2] = 1;
    	for (int i = 3; i < maxn; i++) 
    		supper[i] = (3*(2*i-3)*supper[i-1] - (i-3)*supper[i-2])/i;
    	catalan[0] = catalan[1] = 1;
    	catalan[2] = 2;
    	catalan[3] = 5;
    	for (int i = 4; i < maxn; i++) 
    		for (int j = 0; j < i; j++)
    			catalan[i] += catalan[j] * catalan[i-j-1];
    }
    
    int main() {
    	init();
    	while (scanf("%d", &n) != EOF) {
    		printf("%lld
    ", supper[n]-catalan[n-1]);
    	}
    	return 0;
    }



    版权声明:本文博主原创文章,博客,未经同意不得转载。

  • 相关阅读:
    HDU 3874 Necklace 区间查询的离线操作
    POJ 1651 Multiplication Puzzle (区间dp)
    POJ 2528 Mayor's posters(离散+线段树)
    POJ 2886 Who Gets the Most Candies?
    webgl教程
    GL_ARRAY_BUFFER 和 GL_ELEMENT_ARRAY_BUFFER
    几个不错的webgl教程网
    svg图标库
    sublime text nodejs set
    图形学着色器学习
  • 原文地址:https://www.cnblogs.com/gcczhongduan/p/4800685.html
Copyright © 2011-2022 走看看