UVA 991 - Safe Salutations (卡特兰数)
来源:互联网 发布:软交换网络协议 编辑:程序博客网 时间:2024/05/21 11:05
Safe Salutations
Problem
As any minimally superstitious person knows all too well, terriblethings will happen when four persons do a crossed handshake.
You, an intrepid computer scientist, are given the task of easing theburden of these people by providing them with the feasible set ofhandshakes that include everyone in the group while avoiding any suchcrossings. The following figure illustrates the case for 3 pairs ofpersons:
Input
The input to this problem contains several datasets separated by a blank line. Each dataset is simply an integern, the number ofpairs of people in the group, with 1 ≤ n ≤ 10.
Output
The output is equally simple. For each dataset, print a single integer indicating the numberof possible crossless handshakes that involve everyone in a groupwithn pairs of people. Print a blank line between datasets.
Sample Input
4
Sample Output
14题意:给定n,表示在一个圆上选n对点。求不所有直线不相交的方案有几种。
思路:直线不能穿插。所以对于n对来说,可以选一对直线,那么剩下的必须是偶数,可以分割为0, n -1, 1, n -2 ... n - 1, 0对。所以对于当前的f(n) = f(0)f(n - 1) + f(1)f(n - 2) + f(2)f(n -3) +...+ f(n -1)(0)。显然是一个卡特兰数。由于n只有10.直接递推打表出所有答案。
代码:
#include <stdio.h>#include <string.h>int n, i, j, dp[10];int main() {dp[0] = dp[1] = 1; dp[2] = 2;for (i = 3; i <= 10; i ++)for (j = 0; j < i; j ++) {dp[i] += dp[j] * dp[i - j - 1];}int t = 0;while (~scanf("%d", &n)) {if (t) printf("\n");t ++;printf("%d\n", dp[n]);}return 0;}
- UVA 991 - Safe Salutations (卡特兰数)
- UVa 991 Safe Salutations 卡特兰数
- uva 991 - Safe Salutations(卡特兰数)
- UVA 991 Safe Salutations
- UVa:991 Safe Salutations
- UVa 991 - Safe Salutations
- uva 991 Safe Salutations
- UVA991 - Safe Salutations(catalan数)
- 卡特兰数(Catalan UVa 991 10303 10007 1478)
- uva 11290 - Gangs(卡特兰数)
- Safe Salutations
- 卡特兰数,高精度卡特兰数
- 卡特兰数
- 卡特兰数(Catalan)
- 卡特兰数
- 卡特兰数
- 卡特兰数 大数
- 卡特兰数
- XNA 互動式遊戲設計
- 進階音效控制與管理
- 机房收费系统总结
- 2 維動畫與碰撞偵測
- 抱怨
- UVA 991 - Safe Salutations (卡特兰数)
- hdu 4777 Rabbit Kingdom(离线+树状数组)
- 安卓软件开发的一些知识点。
- C语言数组实现队列
- poj3692
- 圖形特效與文字顯示
- 遊戲畫面管理與切換控制
- 【opencv】特征点检测和追踪--光流法
- C++类对象的内存模型