Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 1776   Accepted: 984   Special Judge

Description

The rhyme scheme for a poem (or stanza of a longer poem) tells which lines of the poem rhyme with which other lines. For example, a limerick such as If computers that you build are quantum
Then spies of all factions will want 'em

Our codes will all fail

And they'll read our email

`Til we've crypto that's quantum and daunt 'em

Jennifer and Peter Shor (http://www.research.att.com/~shor/notapoet.html)

Has a rhyme scheme of aabba, indicating that the first, second and fifth lines rhyme and the third and fourth lines rhyme.

For a poem or stanza of four lines, there are 15 possible rhyme schemes:

aaaa, aaab, aaba, aabb, aabc, abaa, abab, abac, abba, abbb, abbc, abca, a bcb, abcc, and abcd.

Write a program to compute the number of rhyme schemes for a poem or stanza of N lines where N is an input value.

Input

Input
will consist of a sequence of integers N, one per line, ending with a 0
(zero) to indicate the end of the data. N is the number of lines in a
poem.

Output

For
each input integer N, your program should output the value of N,
followed by a space, followed by the number of rhyme schemes for a poem
with N lines as a decimal integer with at least 12 correct significant
digits (use double precision floating point for your computations).

Sample Input

1
2
3
4
20
30
10
0

Sample Output

1 1
2 2
3 5
4 15
20 51724158235372
30 846749014511809120000000
10 115975

Source

 

按照题目所说,double的精度就可以过

第二类Stirling数:将n个不同的元素分成m个集合的问题。

度娘百科:http://baike.baidu.com/link?url=Gf9ql9PnQNNjCZVUgI6SH_o1DgFwpL5yOFalDr_baNqKmrr0unKZvaDNU5RzSGmMQIbKW3Efivp0GPOlz3tcga

别人简洁的题解:http://blog.csdn.net/nvfumayx/article/details/12356847

 /**/
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
double f[][];//[元素数量][分组数量]=方法数
int n;
void init(){
int i,j;
for(i=;i<=;i++) f[][i]=,f[i][]=;
for(i=;i<=;i++)
for(j=;j<=i;j++){
f[i][j]=f[i-][j-]+f[i-][j]*j;
}
return;
}
int main(){
init();
while(scanf("%d",&n) && n){
double ans=;
for(int i=;i<=n;i++)ans+=f[n][i];
printf("%d %.0f\n",n,ans);
}
return ;
}

最新文章

  1. Weblogic集群
  2. Sql Server系列:系统函数
  3. Best Practices for Performance_1、2 memory、Tips 性能和小的优化点、 onTrimMemory
  4. android中基于HTML模板的方式嵌入SWF
  5. R语言学习笔记:字符串处理
  6. Machine Learning in Action &ndash; PCA和SVD
  7. 一键清除cvs/svn 目录
  8. evernote出现“Sync failed due to unexpected problem at server side”的问题
  9. 自定义控件(视图)2期笔记03:自定义控件之使用系统控件(优酷案例之广告条Viewpager)
  10. How can I save HICON to an .ico file
  11. ORACLE主要的系统表和系统视图
  12. 贴近浏览器窗口右侧的jqueryui dialog快速从左侧调整大小时对话框大小设置不准确的问题
  13. 从一个死锁看mysql innodb的锁机制
  14. JAVA IP地址转成长整型方法
  15. ajax实例及实现文本框异步搜素
  16. 运算符重载 与 sort()
  17. python爬虫知识点三--解析豆瓣top250数据
  18. 给定一个数列a1,a2,a3,...,an和m个三元组表示的查询,对于每个查询(i,j,k),输出ai,ai+1,...,aj的升序排列中第k个数。
  19. Leetcode 4.28 Tree Easy
  20. 定时任务框架Quartz-(一)Quartz入门与Demo搭建

热门文章

  1. jenkins重置build序号
  2. Javascript 模块化指北
  3. hprose 1.0(rpc 框架) - 关于跨域和P3P的声明
  4. 18.VUE学习之-v-for操作对象与数值
  5. 迭代器Iterator与语法糖for-each
  6. 描述符应用 -- 让python变成一个强类型的语言
  7. poj 3045 叠罗汉问题 贪心算法
  8. golang echo livereload
  9. 可拖动jquery插件
  10. 【Longest Consecutive Sequence】cpp