130. Circle
time limit per test: 0.25 sec.
memory limit per test: 4096 KB
On a circle border there are 2k different points A1, A2, ..., A2k, located contiguously. These points connect k chords so that each of points A1, A2, ..., A2k is the end point of one chord. Chords divide the circle into parts. You have to find N - the number of different ways to connect the points so that the circle is broken into minimal possible amount of parts P.
Input
The first line contains the integer k (1 <= k <= 30).
Output
The first line should contain two numbers N and P delimited by space.
Sample Input
2
Sample Output
2 3
题意
一个圆上有2k点,请输出点于点之间连线使得所分区域块数最小的方案总数以及区域数
分析
2k个点最少能把平面分成k+1的区域,易证;
至于方案数,利用递推和乘法原理
令a[i]表示2i个点时的方案数,a[0]=a[1]=1,则a[i]=sigma(a[j]*a[i-j-1],0<j<i)
具体参见百度百科:卡特兰数列
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int k,a[31],n;
int i,j;
int main()
{
a[0]=1; //方法
a[1]=1;
a[2]=2;
a[3]=5;
for(i=4;i<=30;i++)
{
a[i]=0;
for(j=1;j<=i;j++)
{
a[i]+=a[j-1]*a[i-j];
}
}
while(~scanf("%d",&k))
{
n=k+1; //最小能分成几个图形
printf("%d %d\n",a[k],n);
}
return 0;
}