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语句,mysql数据库
sql语句,把一张表里的数据,和特定数据(固定常量)新插入另一张表 ,,, from wm_jobpoint INSERT INTO wm_department(departmentcode,depa ...
- https增加临时证书,tomcat配置
1Windows下: 1.1 生成keystore文件及导出证书 打开控制台: 运行: %JAVA_HOME%\bin\keytool -genkey -alias tomcat -keyalg RS ...
- SQLite - WHERE子句
SQLite - WHERE子句 SQLite WHERE子句用于指定一个条件同时抓取数据从一个表或多个表. 如果给定的条件满意,意味着true,然后从表中返回特定值.你会使用WHERE子句来筛选记录 ...
- HDU-6035 Colorful Tree(树形DP) 2017多校第一场
题意:给出一棵树,树上的每个节点都有一个颜色,定义一种值为两点之间路径中不同颜色的个数,然后一棵树有n*(n-1)/2条 路径,求所有的路径的值加起来是多少. 思路:比赛的时候感觉是树形DP,但是脑袋 ...
- C# DateTime.Now函数
// 2008年4月24日 System.DateTime.Now.ToString( " D " );// 2008-4-24 System.DateTime.Now.ToStr ...
- 屏蔽Alt+F4关闭窗体
实现效果: 知识运用: KeyEventArgs类的Alt,Handled属性 public virtual bool Alt {get;} //获取一个值 该值指示是否曾按下Alt键 public ...
- Codeforces Round #277.5 (Div. 2)-D. Unbearable Controversy of Being
http://codeforces.com/problemset/problem/489/D D. Unbearable Controversy of Being time limit per tes ...
- java在线聊天项目 swt可视化窗口Design 重新设计聊天窗口
设计的聊天窗口如下: 制作过程: 首先,在默认的BorderLayout视图下, 上边也就是North处添加一个JPanel,将Layout调整为BorderLayout,West放一个JLabel用 ...
- ios之键盘的自定义
一.键盘通知 当文本View(如UITextField,UITextView,UIWebView内的输入框)进入编辑模式成为first responder时,系统会自动显示键盘.成为firstresp ...
- Cocos2d-X研究之3.0 场景切换特效汇总
Cocos2d-X研究之3.0 场景切换特效汇总 2014-08-05 0个评论 来源:游戏编程 收藏 我要投稿 cocos2d-x 3.0中场景切换特效比较多,而且游戏开 ...