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]的递推了
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define mkp(a,b) make_pair(a,b)
#define pi 3.1415926535897932384626433832795028841971
#define mod 100007
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
LL catlan[];
int main()
{
catlan[]=catlan[]=;
for (int i=;i<=;i++)
for (int j=;j<i;j++)
catlan[i]=(catlan[i]+catlan[j]*catlan[i-j])%mod;
int T=read();
while (T--)printf("%lld\n",catlan[read()-]);
}
Spoj TRNGL
Spoj-TRNGL Make Triangle的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- [LeetCode] Triangle 三角形
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...
- [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, ...
- [LeetCode] Pascal's Triangle 杨辉三角
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...
- 【leetcode】Pascal's Triangle II
题目简述: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Retur ...
- 【leetcode】Pascal's Triangle
题目简述: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5 ...
- SPOJ DQUERY D-query(主席树)
题目 Source http://www.spoj.com/problems/DQUERY/en/ Description Given a sequence of n numbers a1, a2, ...
随机推荐
- sql创建作业--自动执行存储过程
创建自动执行存储过程: 1.创建参数 2.删除已有同名的作业 3. 创建作业 4.创建作业步骤 5.连接服务器 6.创建作业调度 7.启动作业 ALTER PROCEDURE dbo.sx_pro_A ...
- navicate与mysql连接的中文乱码问题
1. 在navicate中查看 show variables like'char%'; show variables like 'collation_%'; 2.在mysql中查看 通过对比可以发现两 ...
- Javascript的一些经验总结
JavaScript作用域 1.作用域 JavaScript的作用域与C.Java等语言不同,它不是以花括号包围的块级作用域,这个特性经常被大多数人忽视.例如下面代码,在大多数类C的语言中会出现变量未 ...
- Thread and Peocess
Thread and Peocess pthread_create() 原型: int pthread_create(pthread_t* thread, pthread_attr_t* attr, ...
- 数组、Math、JOSN总结
json对象: 1.数组有length属性[尽量使用for循环] 2.而json没有length属性[可以使用for...in...循环] 3.for in 不能遍历页面中的节点对象. for ( v ...
- Node.js连接mysql报加密方式错误解决方案
本人在学习全栈开发过程中做一个Node的web项目在连接本地MySQL8.0版本的数据库时,发现Navicat连接不上,它报了一个数据库的加密方式导致连接不上的错误,错误如下: MySQL8.0版本的 ...
- Latex 分块矩阵的处理
在 \(\mathrm{\LaTeX}\) 中,如果想输入类似的矩阵: 可以这样实现: \[ \left[ \begin{array}{cc|cc|c} \lambda & 0 & 1 ...
- win7上安装虚拟机并上网
一.安装Workstation Pro 二.下载CentOS-7-x86_64-DVD-1511.iso包 三.创建新的虚拟机,按照向导安装即可 四.使用cd /etc/sysconfig/netwo ...
- noj-1102-黑白图像
1 //题目地址:http://acm.njupt.edu.cn/acmhome/problemdetail.do?method=showdetail&id=1102 ...
- delphi win7 and high path
Close DelphiLocate bordbk120N.dll (C:\Program Files (x86)\CodeGear\RAD Studio\6.0\bin)Make a backup ...