UVA - 10312 Expression Bracketing
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的更多相关文章
- UVA 10312 - Expression Bracketing(数论+Catalan数)
题目链接:option=com_onlinejudge&Itemid=8&page=show_problem&problem=1253">10312 - Exp ...
- UVa 112 - Tree Summing(树的各路径求和,递归)
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...
- UVa 108 - Maximum Sum(最大连续子序列)
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...
- UVA 442 二十 Matrix Chain Multiplication
Matrix Chain Multiplication Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %l ...
- uva 10718 Bit Mask (位运算)
uva 10718 Bit Mask (位运算) Problem A Bit Mask Time Limit 1 Second In bit-wise expression, mask is a ...
- uva 465 - Overflow 高精度还是浮点数?
uva 465 - Overflow Overflow Write a program that reads an expression consisting of two non-negativ ...
- UVA 11291 Smeech
[来源]https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVa 465 Overflow——WA
上次那个大数开方的高精度的题,UVa113 Power of Cryptography,直接两个double变量,然后pow(x, 1 / n)就A过去了. 怎么感觉UVa上高精度的题测试数据不给力啊 ...
- POJ 题目1145/UVA题目112 Tree Summing(二叉树遍历)
Tree Summing Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8132 Accepted: 1949 Desc ...
随机推荐
- PostgreSQL 序列
PostgreSQL 中的序列是一个数据库对象,本质上是一个自增器.因此,序列在其他同类型数据库软件中以 autoincrment 值的形式存在.在一张表需要非随机,唯一标实符的场景下,Sequenc ...
- [RxJS] Conclusion: when to use Subjects
As a conclusion to this course about RxJS subjects, let's review when and why should you use them. F ...
- matplotlib学习之函数积分图
# coding:utf-8 import numpy as np from matplotlib import pyplot as plt from matplotlib.patches impor ...
- angular的Dom操作
原文 https://www.jianshu.com/p/9d7249922bda 大纲 1.angular的DOM操作 2.为什么不能直接操作DOM? 3.三种错误操作DOM的方式 4.angula ...
- 【搜索引擎Jediael开发笔记】V0.1完整代码 2014-05-26 15:16 443人阅读 评论(0) 收藏
详细代码请见 E:\Project\[重要]归档代码\SearchEngine归档代码 或 https://code.csdn.net/jediael_lu/jediael/tree/10991c83 ...
- (一一六)新浪微博client的离线缓存实现思路
上一节(一一五)利用NSKeyedArchiver实现随意对象转为二进制介绍了将随意对象转化为二进制数据和还原的方法.可用于实现本节介绍的微博数据离线缓存. 通过新浪官方的API能够发现,返回的微博数 ...
- [SQL]远程使用PostgreSQL Studio可视化查看PostgreSQL数据库
1.下载 前往官网地址下载最新的PostgreSQL Studio,我下载的是 pgstudio_1.2-bin .zip,由于我的电脑里面没有tomcat. 假设电脑里有配置好tomcat,能够下载 ...
- Opencv中integral计算积分图
Paul Viola和Michael Jones在2001年首次将积分图应用在图像特征提取上,在他们的论文"Rapid Object Detection using a Boosted Ca ...
- 5.7-基于Binlog+Position的复制搭建
基本环境 Master Slave MySQL版本 MySQL-5.7.16-X86_64 MySQL-5.7.16-X86_64 IP 192.168.56.156 192.168.56.157 ...
- .NET Core微服务之路:不断更新中的目录 (v0.43)
原文:.NET Core微服务之路:不断更新中的目录 (v0.43) 微服务架构,对于从事JAVA架构的童鞋来说,早已不是什么新鲜的事儿,他们有鼎鼎大名的Spring Cloud这样的全家桶框架支撑, ...