题目描述:
130. Circle
time limit per test: 0.5 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个点在圆上均匀分布,里面有k条边,每个点都是边的一个端点,问这些边将圆划分的块最少,问这样的划分方法有多少。
很容易就可以知道,这k条边都不相交的话划分的块是最少的。
那么将2k个点按逆时针编号1到2k,其中奇数编号必定与偶数编号的点有边,否则会出现相交的清况。
又假设编号为1的点是和编号为2j的点相连,那么边(1,2j) 将圆划分成两部分,左边有2×(j-1) 个点,右边有2*(i-j)个点,这2k个点的答案是f(k) 那么f(k)= sum(f(j-1)*f(i-j) ) (1<=j<=i) ;
类似于卡特兰数,由于本题数据范围比较小,没必要推公式,直接暴搞就行。
贴个代码:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<set>
#include<algorithm>
#include<vector>
#include<cstdlib>
#define inf 0xfffffff
#define CLR(a,b) memset((a),(b),sizeof((a)))
#define FOR(a,b) for(int a=1;a<=(b);(a)++)
using namespace std;
int const nMax = 1000;
int const base = 10;
typedef long long LL;
typedef pair<LL,LL> pij;
LL ans[32];
void init(){
ans[1]=1;
ans[0]=1;
for(int i=2;i<32;i++){
ans[i]=0;
for(int j=1;j<=i;j++)ans[i]+=ans[j-1]*ans[i-j];
}
return ;
}
int main(){
int k;
init();
while(cin>>k){
cout<<ans[k]<<" "<<k+1<<endl;
}
return 0;
}