CSU1576: Catalan Square

Description

Input

Output

Sample Input

0

Sample Output

1

HINT

Source

NCPC 2014

题目我没看,直接看公式和输出要求就开始做了,意思就是求公式。。

明显大数,java搞起

import java.util.*;
import java.math.*;

public class Main{
    BigInteger[] Cal = new BigInteger[6000];
    void GetCal(){ 

        Cal[0]=BigInteger.ONE;
        Cal[1]=BigInteger.ONE; 

        for(int i=2;i<=5100;i++)
        {
            BigInteger v1=BigInteger.valueOf(2*i*(2*i-1));
            BigInteger v2=BigInteger.valueOf(i*(i+1));
            Cal[i]=Cal[i-1].multiply(v1).divide(v2);
        }
    } 

    Main()
    {
        Scanner in = new Scanner(System.in);
        int n=in.nextInt();
        GetCal();
        System.out.println(Cal[n+1]);
    } 

    public static void main(String[] args) {
        new Main();
    }
}
时间: 2024-08-04 16:38:53

CSU1576: Catalan Square的相关文章

ncpc-2014 Catalan Square

Catalan Square 注意的是等于Cn+1 高精度卡特兰数 #include<bits/stdc++.h> #define BASE 10000 #define MAX 100010 using namespace std; struct BigInt{ int num[MAX],len; BigInt(int _ = 0) { num[len = 1] = _; } BigInt operator +(const BigInt &a)const { BigInt re; re

[leetcode] 367. Valid Perfect Square

Given a positive integer num, write a function which returns True if num is a perfect square else False. Note: Do not use any built-in library function such as sqrt. Example 1: Input: 16 Returns: True Example 2: Input: 14 Returns: False 使用二分查找寻找input

Project Euler 92:Square digit chains C++

A number chain is created by continuously adding the square of the digits in a number to form a new number until it has been seen before. For example, 44 → 32 → 13 → 10 → 1 → 1 85 → 89 → 145 → 42 → 20 → 4 → 16 → 37 → 58 → 89 Therefore any chain that

LeetCode Maximal Square

Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area. For example, given the following matrix: 1 0 1 0 0 1 0 1 1 1 1 1 1 1 1 1 0 0 1 0 Return 4. 思路分析:这题考察DP.缓存中间结果降低反复计算.DP方程为 if(matrix[i][j

Catalan数

[问题描述]对于一个栈,已知元素的进栈序列,判断一个由栈中所有元素组成的排列的出栈序列. 有N个数,则代表入栈序列为1,2,3,4,5...,N.求所有可能的出栈序列和总数. 代码如下 #include<iostream> #include<vector> #include<algorithm> #include<string> #include<stdio.h> using namespace std; int N = -1; int sum

Theatre Square 题解代码

Theatre Square CodeForces - 1A 水题水题... 最开始的程序是这个,可是AC不了我也不知道为什么......QAQ... #include <stdio.h>#include<stdlib.h>int main(){    int m,n,a,ans,tmp,k,h,tep,i,j;    scanf("%d %d %d",&m,&n,&a);    if(m%a==0)    {        if(n%a

[LeetCode] Matchsticks to Square 火柴棍组成正方形

Remember the story of Little Match Girl? By now, you know exactly what matchsticks the little match girl has, please find out a way you can make one square by using up all those matchsticks. You should not break any stick, but you can link them up, a

【noi 2.6_9288】&amp;【hdu 1133】Buy the Ticket(DP / 排列组合 Catalan+高精度)

题意:有m个人有一张50元的纸币,n个人有一张100元的纸币.他们要在一个原始存金为0元的售票处买一张50元的票,问一共有几种方案数. 解法:(学习了他人的推导后~) 1.Catalan数的应用7的变形.(推荐阅读:http://www.cnblogs.com/chenhuan001/p/5157133.html).P.S.不知我之前自己推出的公式“C(n,m)*C(2*m,m)/(m+1)*P(n,n)*P(m,m)”是否是正确的. (1)在不考虑m人和n人本身组内的排列时,总方案数为C(m+

codeforces 710C C. Magic Odd Square(构造)

题目链接: C. Magic Odd Square Find an n × n matrix with different numbers from 1 to n2, so the sum in each row, column and both main diagonals are odd. Input The only line contains odd integer n (1 ≤ n ≤ 49). Output Print n lines with n integers. All the