zoukankan      html  css  js  c++  java
  • 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
    ",catlan[read()-1]);
    35 }
    Spoj TRNGL
    ——by zhber,转载请注明来源
  • 相关阅读:
    Docker-CentOS系统安装Docker
    Docker-准备Docker环境
    Docker系列-文章汇总
    商品订单库存一致性问题的思考
    java模板、工厂设计模式在项目中的重构
    2018Java年底总结
    java的AQS中enp没有同步代码块为啥是原子操作
    java使用awt包在生产环境docker部署时出现中文乱码的处理
    初探装饰器模式
    开灯问题
  • 原文地址:https://www.cnblogs.com/zhber/p/7152927.html
Copyright © 2011-2022 走看看