Description

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\n", supper[n]-catalan[n-1]);
}
return 0;
}

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

UVA - 10312 Expression Bracketing的更多相关文章

  1. UVA 10312 - Expression Bracketing(数论+Catalan数)

    题目链接:option=com_onlinejudge&Itemid=8&page=show_problem&problem=1253">10312 - Exp ...

  2. UVa 112 - Tree Summing(树的各路径求和,递归)

    题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...

  3. UVa 108 - Maximum Sum(最大连续子序列)

    题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...

  4. UVA 442 二十 Matrix Chain Multiplication

    Matrix Chain Multiplication Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %l ...

  5. uva 10718 Bit Mask (位运算)

    uva 10718  Bit Mask  (位运算) Problem A Bit Mask Time Limit 1 Second In bit-wise expression, mask is a ...

  6. uva 465 - Overflow 高精度还是浮点数?

    uva 465 - Overflow  Overflow  Write a program that reads an expression consisting of two non-negativ ...

  7. UVA 11291 Smeech

    [来源]https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  8. UVa 465 Overflow——WA

    上次那个大数开方的高精度的题,UVa113 Power of Cryptography,直接两个double变量,然后pow(x, 1 / n)就A过去了. 怎么感觉UVa上高精度的题测试数据不给力啊 ...

  9. POJ 题目1145/UVA题目112 Tree Summing(二叉树遍历)

    Tree Summing Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8132   Accepted: 1949 Desc ...

随机推荐

  1. api接口安全以及https

    一:加密方法: 1,对称加密 AES,3DES,DES等,适合做大量数据或数据文件的加解密. 2,非对称加密 如RSA,Rabin.公钥加密,私钥解密.对大数据量进行加解密时性能较低. 二:https ...

  2. 【u251】心灵的抚慰

    Time Limit: 1 second Memory Limit: 128 MB [问题描述] 病毒问题解决后,神牛们的心灵久久不能平静.他可以从一个程序联想到一些相似的程序.比如从程序1联想到2, ...

  3. POJ 1887 Testing the CATCHER(LIS的反面 最大递减子序列)

    Language: Default Testing the CATCHER Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 1 ...

  4. 一次修复IncrediBuild Coordinator服务的经历

    作者:朱金灿 来源:http://blog.csdn.net/clever101 早上发现部门的分布式编译服务的服务端崩溃了,原来是IncrediBuild Coordinator服务启动不了.启动该 ...

  5. 2020发布 .NET 5 下一代全平台 .Net 框架

    [翻译] 正式宣布 .NET 5 2019-05-07 01:18 by Rwing, 16515 阅读, 79 评论, 收藏, 编辑 原文: Introducing .NET 5 今天,我们宣布 . ...

  6. Linux系统编程——线程私有数据

    在多线程程序中.常常要用全局变量来实现多个函数间的数据共享.因为数据空间是共享的,因此全局变量也为全部线程共同拥有. 測试代码例如以下: #include <stdio.h> #inclu ...

  7. auto_create_partition

    #!/usr/bin/env python # -*- encoding: utf8 -*- import calendar import time import os import sys from ...

  8. before/after伪类常见用法

    1.清除浮动 ; } /*IE6/IE7*/ .clearfix:after{ display: block; content: "clear"; ; clear: both; o ...

  9. [Angular] Subscribing to router events

    In our root component, one thing we can do is subscribe to Router events, and do something related t ...

  10. 伸展树(splay tree)

    伸展树的设计思路,鉴于数据访问的局部性(28原则)在实际应用中普遍存在,将按照"最常用者优先"的启发策略.尽管在最坏情况下其单次操作需要 O(n) 时间,但分摊而言仍然 O(log ...