Spoj-TRNGL Make Triangle

 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

 

转载于:https://www.cnblogs.com/zhber/p/7152927.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值