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. POJ 1012 Joseph 约瑟夫问题

    http://poj.org/problem?id=1012 早上去图书馆复习苦逼的复习....万恶的数逻.T T我还要自我安慰的说复习完了奖励回来刷水题~ 10点多的时候外面校运会大吼撑杆跳的那个. ...

  2. 计算机图形学(二)输出图元_3_画线算法_2_DDA算法

    DDA算法        数字微分分析仪(digital differential analyzer, DDA)方法是一种线段扫描转换算法.基于使用等式(3.4)或等式(3.5)计算的&x或& ...

  3. [Swift] Add Scroll View

    import UIKit class AboutViewController : UIViewController @IBOutlet weak var scrollView: UIScrollVie ...

  4. jquery如何实现点击标题收缩下面的内容

    jquery如何实现点击标题收缩下面的内容 一.总结 一句话总结:怎么做复杂前端任务,先把样式(最简单)做出来,然后在写js. 1.如何取jquery集合中的某个索引号的元素? 不是get(),是eq ...

  5. Linux 系统 杀Oracle 进程

    Linux 系统 杀Oracle 进程 杀掉进程用此方法比较好,能保证杀得干净,而不是用SQL  alter system kill kill -9 `ps -ef|grep "oracle ...

  6. 用Apache Ivy实现项目里的依赖管理 分类: C_OHTERS 2014-07-06 18:11 564人阅读 评论(0) 收藏

    Apache Ivy是一个管理项目依赖的工具. 它与Maven  Apache Maven 构建管理和项目管理工具已经吸引了 Java 开发人员的注意.Maven 引入了 JAR 文件公共存储库的概念 ...

  7. USB 3.0规范中译本 第10章 集线器,主机下行口以及设备上行口规范

    本文为CoryXie原创译文,转载及有任何问题请联系cory.xie#gmail.com. 本章描述USB 3.0 集线器的体系结构要求.本章还描述主机下行口和集线器下行口之间功能性的不同之处,以及设 ...

  8. ArcEngine数据编辑--选择要素

    转自原文ArcEngine数据编辑--选择要素 好久没有写博文了,这段时间相对空闲一点,把AE数据编辑实现总结下. 要编辑要素,首先要选中要素,按shift键进行多选,按esc键清空选择. 个人了解的 ...

  9. Arcengine 实现要素选取的方法(转载)

    转自原文Arcengine 实现要素选取的方法(转载) 选择一个要素或者一个要素集(FeatureSelection)的方法很多,如IMap::SelectByShape.ILayer::search ...

  10. VBA Code for Word Navigation Pane 【failed】 view-showheading-method-word

    https://msdn.microsoft.com/VBA/Word-VBA/articles/view-showheading-method-word View.ShowHeading Metho ...