HDU 1131 Count the Trees
卡特兰数再乘上n的阶乘
#include<iostream>
#include<cstdio>
using namespace std;
#define base 10000
#define len 100
void multiply(int a[],int max,int b)
{
int i,array=;
for(i=max-;i>=;i--)
{
array+=b*a[i];
a[i]=array%base;
array/=base; }
} void divide(int a[],int max,int b)
{
int i,div=;
for(i=;i<max;i++)
{
div=div*base+a[i];
a[i]=div/b;
div%=b;
}
} int main()
{
int n,i;
int a[][len];
memset(a[],,len*sizeof(int));
for(i=,a[][len-]=;i<;i++)
{
memcpy(a[i],a[i-],len*sizeof(int));
multiply(a[i],len,*i-);
multiply(a[i],len,i);
divide(a[i],len,i+);
}
while(scanf("%d",&n),n!=)
{
for(i=;i<len&&a[n][i]==;i++);
printf("%d",a[n][i++]);
for(;i<len;i++)
{
printf("%04d",a[n][i]);
}
printf("\n");
}
return ;
}
HDU 1131 Count the Trees的更多相关文章
- Uva 10007 / HDU 1131 - Count the Trees (卡特兰数)
Count the Trees Another common social inability is known as ACM (Abnormally Compulsive Meditation) ...
- HDU 1131 Count the Trees 大数计算
题目是说给出一个数字,然后以1到这个数为序号当做二叉树的结点,问总共有几种组成二叉树的方式.这个题就是用卡特兰数算出个数,然后因为有编号,不同的编号对应不同的方式,所以结果是卡特兰数乘这个数的阶乘种方 ...
- hdu 1130,hdu 1131(卡特兰数,大数)
How Many Trees? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- zjuoj 3602 Count the Trees
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3602 Count the Trees Time Limit: 2 Seco ...
- Count the Trees[HDU1131]
Count the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- HDU——1130 How Many Trees?
How Many Trees? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- HDU 3336 Count the string(KMP的Next数组应用+DP)
Count the string Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 1693 Eat the Trees——插头DP
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1693 第一道插头 DP ! 直接用二进制数表示状态即可. #include<cstdio> # ...
- HDU 5901 Count primes 论文题
Count primes 题目连接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5901 Description Easy question! C ...
随机推荐
- mysql之数据库特性认识
最近面试经常被面试官问道关于数据库方面的知识,于是总结一下面试官问的题以及自己对数据库的认识 1.之前百度面试官问了我一个特别基础的sql问题:如何清除表的所有记录,以前在学校做项目开发的时候有使用过 ...
- Convert Binary Search Tree (BST) to Sorted Doubly-Linked List
(http://leetcode.com/2010/11/convert-binary-search-tree-bst-to.html) Convert a BST to a sorted circu ...
- 用U盘和iso镜像文件重装系统
工具: 1.硬件: 容量最好在2.5G以上u盘(比如这次是2.3G的winows_7_32位_中文专业版ISO,我的U盘容量是不到8G). 2.软件: a.Ultraiso软件,来制作u盘启动项 b. ...
- Delphi 2010下载+完美破解
点击链接进入http://altd.embarcadero.com/download/RADStudio2010/delphicbuilder_2010_3615_win.isoRAD Studio/ ...
- java附件上传下载磁盘版
ACTION public class UploadAction extends BaseAction { private static final long serialVersionUID = 1 ...
- django学习之Model(五)MakingQuery
接着上篇. 10-一次更新多个对象 有时想要对QuerySet中的所有对象的某一个field来设定一个值,这时候可以像下边这样用update(): # Update all the headlines ...
- finally块的问题(finally block does not complete normally) (转)
当finall块中包含return语句时,Eclipse会给出警告“finally block does not complete normally”,原因分析如下: 1.不管try块.catch块中 ...
- 脑波设备mindwave数据流二次开发示例
数据流开发神念科技提供了两个文件ThinkGearStreamParse.h和ThinkGearStreamParse.cpp两个文件,主要接口为: 宏定义: /* Data CODE definit ...
- spring集成mongodb封装的简单的CRUD
1.什么是mongodb MongoDB是一个基于分布式文件存储的数据库.由C++语言编写.旨在为WEB应用提供可扩展的高性能数据存储解决方案. mongoDB MongoDB是一个介 ...
- JavaScript中你可能不知道的九件事
今天凑巧去W3School扫了一遍JavaScript教程,发现从中看到了不少自己曾经没有注意过的细节. 我这些细节列在这里.分享给可能相同不知道的朋友: 1.使用 document.write() ...