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