UVA 991 - Safe Salutations (卡特兰数)

避交叉握手问题

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 integer n, 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 groupwith n 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;
}


标题基于Python的自主学习系统后端设计与实现AI更换标题第1章引言介绍自主学习系统的研究背景、意义、现状以及本文的研究方法和创新点。1.1研究背景与意义阐述自主学习系统在教育技术领域的重要性和应用价值。1.2国内外研究现状分析国内外在自主学习系统后端技术方面的研究进展。1.3研究方法与创新点概述本文采用Python技术栈的设计方法和系统创新点。第2章相关理论与技术总结自主学习系统后端开发的相关理论和技术基础。2.1自主学习系统理论阐述自主学习系统的定义、特征和理论基础。2.2Python后端技术栈介绍DjangoFlask等Python后端框架及其适用场景。2.3据库技术讨论关系型和非关系型据库在系统中的应用方案。第3章系统设计与实现详细介绍自主学习系统后端的设计方案和实现过程。3.1系统架构设计提出基于微服务的系统架构设计方案。3.2核心模块设计详细说明用户管理、学习资源管理、进度跟踪等核心模块设计。3.3关键技术实现阐述个性化推荐算法、学习行为分析等关键技术的实现。第4章系统测试与评估对系统进行功能测试和性能评估。4.1测试环境与方法介绍测试环境配置和采用的测试方法。4.2功能测试结果展示各功能模块的测试结果和问题修复情况。4.3性能评估分析分析系统在高并发等场景下的性能表现。第5章结论与展望总结研究成果并提出未来改进方向。5.1研究结论概括系统设计的主要成果和技术创新。5.2未来展望指出系统局限性并提出后续优化方向。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值