UVA-10312 Expression bracketing

Source: Internet
Author: User

Description

Problem A

Expression bracketing

input: standard input

output: standard output

Time Limit: 1 second

Memory Limit: MB

Inthis problem you'll have to find on how many waysn letters can being bracketed so that's the bracketing is Non-bin Arybracketing. For example4 lettershave 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 is not binary. Given the number of letters you'll have a 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 withn letters.

Sample Input

3

4

5

10

Sample Output

1

6

31

98187

Test instructions: suppose P. Q is the string of requirements, then (p. Q) is also satisfied. To ask for all the impossible conditions

Thought: We first to satisfy, can imagine, this and Cattleya number of ideas is similar, are the string into (1, n-1), (2, n-2) .... Considered, but the whole situation may be difficult to find. After understanding is a call

Super Catalan number sequence, subtract results, but note that Cattleya numbers start from 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] = Suppe R[2] = 1;for (int i = 3; i < MAXN; i++) Supper[i] = (* * (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\n", Supper[n]-catalan[n-1]);} return 0;}



Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.

UVA-10312 Expression bracketing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.