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. 使用doxygen为C/C++程序生成中文文档

    文章来自:http://www.fmddlmyy.cn/text21.html 依照约定的格式凝视源码,用工具处理凝视过的源码产生文档.通过这样的方式产生文档至少有下面优点: 便于代码和文档保持同步. ...

  2. 如何使用google地图的api(整理)

    如何使用google地图的api(整理) 一.总结 一句话总结:直接用script标签引google地图api即可. 1.如何使用google地图的api? 页面引用javascript文件<s ...

  3. LibCurl HTTP部分详细介绍

    目录索引: 一.LibCurl基本编程框架 二.一些基本的函数 三.curl_easy_setopt函数部分选项介绍 四.curl_easy_perform 函数说明(error 状态码) 五.lib ...

  4. iOS开发之Quartz2D 六 绘制UIImageView

    #import <UIKit/UIKit.h> @interface XMGImageView : UIView /** <#注释#> */ @property (nonato ...

  5. Android JAVA中的时间大小比较

    import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; imp ...

  6. 利用C#与AE调用GP工具

    转自原文 利用C#与AE调用GP工具 第一,首先要明确自己需要调用arctoolbox里面的什么工具,实现什么样的功能. 第三,编写command或tool工具,编写自己要的功能工具. 1)首先创建一 ...

  7. iOS开发Block的介绍以及Block的循环引用问题

    1:block的循环引用问题最主要记住两点: 如果[block内部]使用[外部声明的强引用]访问[对象A], 那么[block内部]会自动产生一个[强引用]指向[对象A] 如果[block内部]使用[ ...

  8. ps如何制作gif(窗口->动画)(导出:存储为Web和设备所用格式)

    ps如何制作gif(窗口->动画)(导出:存储为Web和设备所用格式) 一.总结 1.点击窗口,选择动画 2.导出的时候:存储为Web和设备所用格式 二.ps如何制作gif 1.首先我们安装并打 ...

  9. android studio 2.2 使用cmake编译NDK

    Android studio 2.2 已经进入beta版本,新功能添加众多,NDK编程也得到了简化.官方博客介绍.本文介绍如何使用新版android studio调用 c++代码,为了超级通俗易懂,例 ...

  10. Surf算法特征点检测与匹配

    Speeded Up Robust Features(SURF,加速稳健特征),是一种稳健的局部特征点检测和描述算法.最初由Herbert Bay发表在2006年的欧洲计算机视觉国际会议(Europe ...