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

  1. Input:
  2. 2
    3
    5
  3.  
  4.  Output:
  5. 1
    5
  6.  
  7. 很迷……答案显然就是卡特兰数
    然后在计算的时候出现了一些小小的偏差
    c[i]=c[i-1]*(4i-2)/(i+1)的递推式是不行的,因为特么取模的1e5+7不是质数,i+1的逆元怎么搞啊……
    然后用n^2c[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=,f=;char ch=getchar();
  22. while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
  23. while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
  24. return x*f;
  25. }
  26. LL catlan[];
  27. int main()
  28. {
  29. catlan[]=catlan[]=;
  30. for (int i=;i<=;i++)
  31. for (int j=;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()-]);
  35. }

Spoj TRNGL

Spoj-TRNGL Make Triangle的更多相关文章

  1. SPOJ #453. Sums in a Triangle (tutorial)

    It is a small fun problem to solve. Since only a max sum is required (no need to print path), we can ...

  2. UVALive 4639 && SPOJ SPOINTS && POJ 3805 && AOJ 1298 Separate Points 求两个凸包是否相交 难度:3

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

  3. BZOJ 2588: Spoj 10628. Count on a tree [树上主席树]

    2588: Spoj 10628. Count on a tree Time Limit: 12 Sec  Memory Limit: 128 MBSubmit: 5217  Solved: 1233 ...

  4. [LeetCode] Triangle 三角形

    Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...

  5. [LeetCode] Pascal's Triangle II 杨辉三角之二

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...

  6. [LeetCode] Pascal's Triangle 杨辉三角

    Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...

  7. 【leetcode】Pascal's Triangle II

    题目简述: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Retur ...

  8. 【leetcode】Pascal's Triangle

    题目简述: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5 ...

  9. SPOJ DQUERY D-query(主席树)

    题目 Source http://www.spoj.com/problems/DQUERY/en/ Description Given a sequence of n numbers a1, a2, ...

随机推荐

  1. tomcat 发布本地文件

    应用场景,通过web,jsp访问本地mouse文件夹的静态文件 通过修改tomcat配置文件server.xml <!--在Host标签下加入Context标签,path指的是服务器url请求地 ...

  2. win7 ghost 纯净版最新系统下载

    这个系统是WIN7系统GHOST版装机旗舰版 SP1,更新了系统补丁到2016-02(可通过微软漏洞扫描和卫士漏洞扫描),升级Internet Explorer为IE9,增加数款驱动的支持,支持最新的 ...

  3. stringstream类的简介和用法

    一.简介 <sstream>类库定义了三种类:istringstream,ostringstream,stringstream.分别用来进行流的输入,流的输出,输入输出操作.在此演示str ...

  4. urllib基础-利用网站结构爬取网页-百度搜索

    有的时候爬取网页,可以利用网站额结构特点爬取网页 在百度搜索框中输入搜索内容,单击搜索,浏览器会发送一个带有参数的url请求.尝试删除其中的一些参数,只剩下wd这个参数.发现wd是搜索内容.这样程序可 ...

  5. C语言格式化说明符

    1.1.1 格式化输入输出函数一.printf()函数printf()函数是格式化输出函数, 一般用于向标准输出设备按规定格式输出信息.在编写程序时经常会用到此函数.printf()函数的调用格式为: ...

  6. vue 封装组件上传img

    var _uploadTemplate = '<div>'+ '<input type="file" name="file" v-on:cha ...

  7. [UVA] 704 Colour Hash

    所谓"周界搜索",练习搜索的好题,双向宽搜/迭代加深均可,还有很多细节有待完善,判重有比set更优的结构,宽搜还没写,先存一下. //Writer:GhostCai &&a ...

  8. mysql8忘记root密码修改密码(mac)

    0.在/etc/my.cnf修改验证方式 [mysqld] default_authentication_plugin=mysql_native_password 1.切换root权限: sudo s ...

  9. Vue.js—单元测试

    Vue.js--测试 这里采用的是Vue官方工具(Vue-CLI)搭建出来的项目,在这个搭建工具中推荐的两种测试分别是 端到端的测试 E2E 单元测试 Unit Test 端到端的测试(E2E) E2 ...

  10. CSS3-transform-style

    transform-style属性 transform-style属性是3D空间一个重要属性,指定嵌套元素如何在3D空间中呈现.他主要有两个属性值:flat和preserve-3d. transfor ...