hdu1023卡特的问题
请教一个hdu1023卡特的问题。求解答hdu1023
-
import java.math.BigInteger;
-
import java.util.Scanner;
-
public class Main
-
{
-
static BigInteger fac(BigInteger n)
-
{
-
BigInteger result=BigInteger.ONE;
-
for(BigInteger i=BigInteger.ONE;!i.equals(n.add(BigInteger.ONE));i=i.add(BigInteger.ONE))
-
{
-
result=result.multiply(i);
-
}
-
return result;
-
}
-
public static void main(String args[])
-
{
-
Scanner cin=new Scanner(System.in);
-
while(cin.hasNext())
-
{
-
BigInteger n=cin.nextBigInteger();
-
BigInteger total=fac(n.add(n)).divide(n.add(BigInteger.ONE).multiply(fac(n).pow(2)));
-
System.out.println(total.toString());
-
}
-
}
-
}
hdu 1023 卡特兰数经典
#include <iostream>
using
namespace
std;
int
a[105][105];
int
b[105];
void
catalan()
//求卡特兰数
{
int
i, j, len, carry, temp;
a[1][0] = b[1] = 1;
len = 1;
for
(i = 2; i <= 100; i++)
{
for
(j = 0; j < len; j++)
//乘法
a[i][j] = a[i-1][j]*(4*(i-1)+2);
carry = 0;
for
(j = 0; j < len; j++)
//处理相乘结果
{
temp = a[i][j] + carry;
a[i][j] = temp % 10;
carry = temp / 10;
}
while
(carry)
//进位处理
{
a[i][len++] = carry % 10;
carry /= 10;
}
carry = 0;
for
(j = len-1; j >= 0; j--)
//除法
{
temp = carry*10 + a[i][j];
a[i][j] = temp/(i+1);
carry = temp%(i+1);
}
while
(!a[i][len-1])
//高位零处理
len --;
b[i] = len;
}
}
int
main(
int
argc,
char
*argv[])
{
int
n,i;
catalan();
int
j;
while
(cin >> n)
{
for
(j = b[n] - 1; j >= 0; j--)
{
printf
(
"%d"
,a[n][j]);
}
printf
(
"\n"
);
}
return
0;
}
更多关注微信:xllx999
-
2019最新创业方法(附:上百个互联网创业成功案例)
2019-10-24浏览:15365
-
99%的大型企业产品运营都是这么做的(借助互联网思维来做产品运营)
2019-10-24浏览:9342
-
快速增加流量的方法(适合任意行业的网络推广技巧)
2019-10-24浏览:35264
-
虎门大桥恢复交通后车流顺畅
06-12浏览:1382
-
虎门大桥涡振是什么意思 虎门大桥简介
06-12浏览:1799
-
怎么样把一件事情做成功呢?
06-07浏览:123
-
全栈工程师自述:我的编程能力为什么突飞猛进?| 知乎4千4百赞
11-22浏览:1167
-
又一起相互宝拒赔案例,投保的时候得当心了
11-22浏览:1850