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 ...
随机推荐
- Spring Boot 静态资源处理(转)
Spring Boot 静态资源处理 Spring Boot 系列 Spring Boot 入门 Spring Boot 属性配置和使用 Spring Boot 集成MyBatis Spring Bo ...
- php修改SESSION的有效生存时间
如何修改SESSION的生存时间 我们来手动设置 Session 的生存期: <?phpsession_start(); // 保存一天 $lifeTime = 24 * 3600; setco ...
- (二)RabbitMQ消息队列-RabbitMQ消息队列架构与基本概念
原文:(二)RabbitMQ消息队列-RabbitMQ消息队列架构与基本概念 没错我还是没有讲怎么安装和写一个HelloWord,不过快了,这一章我们先了解下RabbitMQ的基本概念. Rabbit ...
- [Javascript] Case insensitive sorting for string arrays
We look at the default Array.prototype.sort behavior and discuss how you can do case insensitive str ...
- Centos6.5 网络配置
网络配置 本教程配置说明 以下为本教程安装时的配置,用户依据实际情况进行调整 * 在root用户权限下安装下完毕 * IP地址设置为 10.10.108.160 * 本机DNS设置为 8.8.8.8 ...
- php实现求数组中出现次数超过一半的数字(isset($arr[$val]))(取不同数看剩)(排序取中)
php实现求数组中出现次数超过一半的数字(isset($arr[$val]))(取不同数看剩)(排序取中) 一.总结 1.if(isset($arr[$val])) $arr[$val]++; //1 ...
- [Vue] Parent and Child component communcation
By building components, you can extend basic HTML elements and reuse encapsulated code. Most options ...
- 【codeforces 758C】Unfair Poll
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- js如何实现动态显示表格数据(点奇数显示奇数单元格内容)
js如何实现动态显示表格数据(点奇数显示奇数单元格内容) 一.总结 一句话总结: 1.动态指定表格中每个单元格的id,然后通过id可以获取每个单元格,然后对里面的innerHTML进行赋值. 2.弄了 ...
- 社会化登录分享-Android SDK的二次封装和使用
本系列文章将第三方的登录分享功能进行二次封装,统一接口调用,简化了接不同平台登录分享的步骤. 0 系列文章 系列一 Android SDK的二次封装和使用 系列二 源码解析 系列三 微信SDK接入 系 ...