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, ...
随机推荐
- selenium-Python之定位下拉框选择
1.通过select 进行定位下拉框 下拉框如图所示 通过代码定位 #通过index进行选择Select(driver.find_element_by_id("cardType") ...
- make 与makefile(会不会写 makefile,从一个侧面说明了一个人是否具备完成大型工程的能力。)
跟我一起写 Makefile /**/ 陈皓 (CSDN) 概述 —— 什么是makefile?或许很多Winodws的程序员都不知道这个东西,因为那些Windows的IDE都为你做了这个工作,但我觉 ...
- The - Modcrab——使用贪心策略
一.题目信息 The - Modcrab 简单翻译一下:Vova有生命值h1,每次攻击值为a1,每瓶药水恢复生命值c1;Modcrab有生命值h2,每次攻击值为a2.在每个关卡开始,Vova有两种选择 ...
- Node.js连接mysql报加密方式错误解决方案
本人在学习全栈开发过程中做一个Node的web项目在连接本地MySQL8.0版本的数据库时,发现Navicat连接不上,它报了一个数据库的加密方式导致连接不上的错误,错误如下: MySQL8.0版本的 ...
- win10 多桌面 win+tab | ctrl+win+左右箭头
win10 多桌面 win+tab | ctrl+win+左右箭头
- ValueError: option names {'--alluredir'} already added 报错
运行测试用例 import pytest from WXP2P_2.test_data2.login_case import logindata_error1,logindata_error2,log ...
- k8s 如何 Failover?
上一节我们有 3 个 nginx 副本分别运行在 k8s-node1 和 k8s-node2 上.现在模拟 k8s-node2 故障,关闭该节点. 等待一段时间,Kubernetes 会检查到 k8s ...
- ZOJ-1360 || POJ-1328——Radar Installation
ZOJ地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=360 POJ地址:http://poj.org/problem?id ...
- JS设置组合快捷键
为提升用户体验,想要在web页面中通过组合快捷键调出用户帮助页面,具体实现思路是监听keyup事件,在相应的处理函数中进行逻辑编写,代码如下 $(document).keyup(function (e ...
- bzoj3545 [ONTAK2010]Peaks、bzoj3551 [ONTAK2010]Peaks加强版
题目描述: bzoj3545,luogu bzoj3551 题解: 重构树+线段树合并. 可以算是板子了吧. 代码(非强制在线): #include<cstdio> #include< ...