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 ;
}

POJ1671 Rhyme Schemes的更多相关文章

  1. 2019上海网络赛 F. Rhyme scheme 普通dp

    Rhyme scheme Problem Describe A rhyme scheme is the pattern of rhymes at the end of each line of a p ...

  2. 别人整理的DP大全(转)

    动态规划 动态规划 容易: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ...

  3. dp题目列表

    此文转载别人,希望自己能够做完这些题目! 1.POJ动态规划题目列表 容易:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 11 ...

  4. poj 动态规划题目列表及总结

    此文转载别人,希望自己能够做完这些题目! 1.POJ动态规划题目列表 容易:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 11 ...

  5. [转] POJ DP问题

    列表一:经典题目题号:容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1191,1208, 1276, 13 ...

  6. poj动态规划列表

    [1]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 13 ...

  7. POJ动态规划题目列表

    列表一:经典题目题号:容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1191,1208, 1276, 13 ...

  8. POJ 动态规划题目列表

    ]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 1322 ...

  9. HOJ题目分类

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

随机推荐

  1. MySQL - 在sql语句执行时是先执行触发器再检查约束条件的

    在sql语句执行时是先执行触发器再检查约束条件的

  2. python 用requests请求,报SSL:CERTIFICATE_VERIFY_FAILED错误

    https://www.aliyun.com/jiaocheng/437481.html

  3. 自动化运维工具——ansible剧本playbook(三)

    一.Playbook--Ansible剧本 playbook是由一个或多个 "play"组成的列表 play的主要功能在于将事先归并为一组的主机装扮成事先通过ansible中的ta ...

  4. Linux清空mysql所有数据

    1,删除data目录下所有文件 rm -rf /usr/local/mysql5/data/* 2,mysql_install_db脚本初始化Mysql /usr/local/mysql5/scrip ...

  5. 22.VUE学习之-replice删除当前评论条数

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. JVM 内存分配和回收策略

    对象的内存分配,主要是在java堆上分配(有可能经过JIT编译后被拆为标量类型并间接地在栈上分配),如果启动了本地线程分配缓冲,将按线程优先在TLAB上分配.少数情况下也是直接分配到老年代,分配规则不 ...

  7. Android四大基本组件介绍及生命周期

    Android四大基本组件分别是Activity,Service服务,Content Provider内容提供者,BroadcastReceiver广播接收器. 一.了解四大基本组件 Activity ...

  8. Codeforces:68A-Irrational problem(暴力大法好)

    A- Irrational problem p Time Limit: 2000MS Memory Limit: 262144K 64bit IO Format: %I64d& %I64 De ...

  9. [USACO]奶牛博览会(DP)

    Description 奶牛想证明他们是聪明而风趣的.为此,贝西筹备了一个奶牛博览会,她已经对N头奶牛进行了面试,确定了每头奶牛的智商和情商. 贝西有权选择让哪些奶牛参加展览.由于负的智商或情商会造成 ...

  10. RAID与LVM磁盘阵列技术

    RAID(Redundant Array of Independent Disks,独立冗余磁盘阵列) RAID概念: RAID技术通过把多个硬盘设备组合成一个容量更大.安全性更好的磁盘阵列,并把数据 ...