在线编程在线课堂在线测评Anycodes在线编程

编程论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

How to use bs4??
本帖最后由 carry0987 于
Double Queue 问题描述 : The new founded Balkan Investment Group Bank (
John 问题描述 : Little John is playing very funny game
linux-command Linux命令大全搜索工具,内容包含Linux命令
Coati 是一款跨平台的代码查看工具,适用于 C/C++ 和 Java。商业软件。特性:1. 索引
系统可承载海量并发,消息收发确认机制 保障消息必达 系统采用动态智
全平台视频监控,支持安卓苹果以及pcweb,支持海康大华等主流dvr,全部源码以及文档 单聊、群聊、商
如何访问类的私有属性? 下面以 TPathData 为例,
问题:从 XE4 以来,Firemonkey 曲线绘图在移动平台不平滑的问题一直令人诟病,提交到官方的 QC 也是族繁不及备载,官方似乎有意的
操作数据库(RODBC)   odbcConnect(dsn, uid="", p
数据模式:mode函数显示任何对象的模式。常见的单个的
系统可承载海量并发,消息收发确认机制 保障消息必达 系统采用动态智
RabbitMQ与PHP(一) 项
Iease团队扩编预备中,盼望能有Ruby或者java工程师加盟。全职兼职都可以。有爱好的伴侣请与我接洽。 邮件:i
ruby 怎么设置装备摆设GTK2,求教指导下!
#include #include #include #include using namespace std; int main() {
标题如图所示: 有n盏灯,编号1~n。一开端灯都是关着的
成熟的消息收发确认机制,支持万人大群 支持开发自定义的消息sdk接口,扩展性超强 支持单/
成熟的消息收发确认机制,支持万人大群 支持开发自定义的消息sdk接口,扩展性超强 支持单/
1. 注意列表和集合的区别 set 列表表现形式: list_1
Ajax   Ajax即“Asynchronous Javascript And
大师好,我比来在做布谷鸟优
分辨提取A和B图像Harris角点,接下来须要对

[HDU杭电] HDU 1131 Count the Trees -数论应用-[解题报告] C++

[复制链接]
发表于 2016-3-26 22:17:52 | 显示全部楼层 |阅读模式
Count the Trees  


问题描述 :
Another common social inability is known as ACM (Abnormally Compulsive Meditation). This psychological disorder is somewhat common among programmers. It can be described as the temporary (although frequent) loss of the faculty of speech when the whole power of the brain is applied to something extremely interesting or challenging.
Juan is a very gifted programmer, and has a severe case of ACM (he even participated in an ACM world championship a few months ago). Lately, his loved ones are worried about him, because he has found a new exciting problem to exercise his intellectual powers, and he has been speechless for several weeks now. The problem is the determination of the number of different labeled binary trees that can be built using exactly n different elements. For example, given one element A, just one binary tree can be formed (using A as the root of the tree). With two elements, A and B, four different binary trees can be created, as shown in the figure.

HDU 1131 Count the Trees -数论应用-[解题报告] C++

HDU 1131 Count the Trees  -数论应用-[解题报告] C++

If you are able to provide a solution for this problem, Juan will be able to talk again, and his friends and family will be forever grateful.  
输入:
The input will consist of several input cases, one per line. Each input case will be specified by the number n ( 1 ≤ n ≤ 100 ) of different elements that must be used to form the trees. A number 0 will mark the end of input and is not to be processed.  
输出:
For each input case print the number of binary trees that can be built using the n elements, followed by a newline character.
样例输入:

  1. 1
  2. 2
  3. 10
  4. 25
  5. 0
复制代码
样例输出:

  1. 1
  2. 4
  3. 60949324800
  4. 75414671852339208296275849248768000000
复制代码
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cmath>
  4. using namespace std;
  5. int a[1001];
  6. void mul(int a[],int b)
  7. {
  8.         int i;
  9.         for(i=0;i<1001;i++)
  10.                 a[i]*=b;
  11.         for(i=0;i<1000;i++)
  12.                 if(a[i]>=10)
  13.                 {
  14.                         a[i+1]+=a[i]/10;
  15.                         a[i]%=10;
  16.                 }
  17. }
  18. int main()
  19. {
  20.         int n;
  21.         while(scanf("%d",&n)!=EOF&&n)
  22.         {
  23.                 int i;
  24.                 for(i=0;i<1001;i++)
  25.                         a[i]=0;
  26.                 a[0]=1;
  27.                 for(i=n+2;i<=2*n;i++)
  28.                         mul(a,i);
  29.                 i=1000;
  30.                 while(!a[i]&&i>0)
  31.                         i--;
  32.                 for(;i>0;i--)
  33.                         printf("%d",a[i]);
  34.                 printf("%d/n",a[0]);
  35.         }
  36.         return 0;
  37. }
复制代码
在线编程(http://www.anycodes.cn)&编程论坛(http://www.52exe.cn)感谢您的支持!
回复

使用道具 举报

发布主题 上个主题 下个主题 快速回复 返回列表 官方QQ群
在线客服
客 服 中 心
群 机 器 人
网站二维码
收 起 客 服

QQ|Archiver|手机版|小黑屋|Anycodes ( ICP14002806Anycodes在线编程

GMT+8, 2018-11-15 04:46 , Processed in 1.467444 second(s), 71 queries .

Powered by Anycodes

© 2001-2013 吉林市群龙科技有限公司 Inc.

快速回复 返回顶部 返回列表