POJ 2084 Game of Connections】的更多相关文章

卡特兰数. #include<stdio.h> #include<string.h> ; ; void mul(__int64 a[],int len,int b) { int i; __int64 jw=; ;i>=;i--) { jw=jw+a[i]*b; a[i]=jw%base; jw=jw/base; } } void div(__int64 a[],int len,int b) { int i; __int64 jw=; ;i<lenth;i++) { jw…
package com.njupt.acm; import java.math.BigInteger; import java.util.Scanner; public class POJ_2084 { public static void main(String[] args) { BigInteger catalan[] = new BigInteger[102]; catalan[1] = new BigInteger("1"); BigInteger one = new Big…
卡特兰数源于组合数学,ACM中比较具体的使用例子有,1括号匹配的种数.2在栈中的自然数出栈的种数.3求多边形内三角形的个数.4,n个数围城圆圈,找不相交线段的个数.5给定n个数,求组成二叉树的种数…… 此题就是第4个样例,是裸卡特兰数,但是这里牵扯的大数,可以使用java的大数类解决,但是我这里使用高精度乘法和除法模拟的(主要是java不会). 此处的递推式为H[1] = 1:H[n] = H[n-1]*(4*n-2)/(n+1){n>=2}:代码如下: 需要注意输出的形式,我这里的进制是100…
看了下大牛们的,原来这题是卡特兰数,顺便练练java.递归式子:h(0)=1,h(1)=1   h(n)= h(0)*h(n-1) + h(1)*h(n-2) + ... + h(n-1)h(0) (其中n>=2)   打表172MS import java.math.BigInteger; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in=new S…
POJ 2084 /**************************************** * author : Grant Yuan * time : 2014/10/19 15:42 * source : POJ 2084 * algorithm: Catalan数+高精度 * ***************************************/ import java.io.*; import java.math.*; import java.util.*; publ…
Game of Connections Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 8664   Accepted: 4279 Description This is a small but ancient game. You are supposed to write down the numbers 1, 2, 3, . . . , 2n - 1, 2n consecutively in clockwise ord…
Game of Connections Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 8772   Accepted: 4324 Description This is a small but ancient game. You are supposed to write down the numbers 1, 2, 3, . . . , 2n - 1, 2n consecutively in clockwise ord…
第一题组合数学题.可以使用递推,设1与其他各数分别连边,假设N=3;若1-4,则圆分成两部分计数,此时可以利用乘法原理.(高精度) #include <cstdio> #include <cstring> #include <iostream> #include <string> using namespace std; const int maxn = 200; struct bign { int len, s[maxn]; bign() { memset…
Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. (5)构造法.(poj3295) (6)模拟法.(poj1068,poj2632,poj1573,poj2993,poj2996) 二.图算法: (1)图的深度优先遍历和广度优先遍历. (2)最短路…
初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推.     (5)构造法.(poj3295)     (6)模拟法.(poj1068,poj2632,poj1573,poj2993,poj2996)二.图算法:     (1)图的深度优先遍历和广度优先遍历.     (2)最短路径算法(dijkstra,bellman-ford,floyd,hea…