zhber
有好多做过的题没写下来,如果我还能记得就补吧

 Make Triangle

Chayanika loves Mathematics. She is learning a new chapter geometry. While reading the chapter a question came in her mind. Given a convex polygon of n sides. In how many ways she can break it into triangles, by cutting it with (n-3) non-adjacent diagonals and the diagonals do not intersect.

 

Input

First line of the input will be an integer t (1<=t<=100000) which is the no of test cases. Each test case contains a single integer n (3<=n<=1000) which is the size of the polygon.

Output

For each test case output the no of ways %100007.

Example

Input:
2
3
5

 Output: 1
5

很迷……答案显然就是卡特兰数
然后在计算的时候出现了一些小小的偏差
c[i]=c[i-1]*(4i-2)/(i+1)的递推式是不行的,因为特么取模的1e5+7不是质数,i+1的逆元怎么搞啊……
然后用n^2的c[k]*c[i-k]的递推了
 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cstring>
 4 #include<cstdlib>
 5 #include<algorithm>
 6 #include<cmath>
 7 #include<queue>
 8 #include<deque>
 9 #include<set>
10 #include<map>
11 #include<ctime>
12 #define LL long long
13 #define inf 0x7ffffff
14 #define pa pair<int,int>
15 #define mkp(a,b) make_pair(a,b)
16 #define pi 3.1415926535897932384626433832795028841971
17 #define mod 100007
18 using namespace std;
19 inline LL read()
20 {
21     LL x=0,f=1;char ch=getchar();
22     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
23     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
24     return x*f;
25 }
26 LL catlan[1010];
27 int main()
28 {
29     catlan[1]=catlan[0]=1;
30     for (int i=2;i<=1000;i++)
31         for (int j=0;j<i;j++)
32             catlan[i]=(catlan[i]+catlan[j]*catlan[i-j])%mod;
33     int T=read();
34     while (T--)printf("%lld\n",catlan[read()-1]);
35 }
Spoj TRNGL

 

posted on 2017-07-11 22:26  zhber  阅读(250)  评论(0编辑  收藏  举报