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. vue学习之路 - 3.基本操作(中)

    基本操作(中) 本章节主要介绍:vue的条件渲染.列表渲染,计算属性和侦听器 条件渲染和列表渲染 条件渲染主要使用到了 v-if 指令,列表渲染主要使用了 v-for 指令. 下面介绍 v-if .  ...

  2. cf550C. Divisibility by Eight(结论)

    题意 给出长度为$n$的字符串,判断是否能删除一些数后被$8$整除 Sol 神仙题啊Orz 结论: 若数字的后三位能被$8$整除,则该数字能被$8$整除 证明 设$x = 10000 * a_i + ...

  3. [Hdu3652]B-number(数位DP)

    Description 题目大意:求小于n是13的倍数且含有'13'的数的个数. (1 <= n <= 1000000000) Solution 数位DP,题目需要包含13,且被13整除, ...

  4. 大数模板Java

    import java.util.*; import java.math.BigInteger; public class Main{ public static void main(String a ...

  5. P3116 [USACO15JAN]会议时间Meeting Time

    P3116 [USACO15JAN]会议时间Meeting Time 题目描述 Bessie and her sister Elsie want to travel from the barn to ...

  6. 37、iamgeview 图层叠加

    1 Drawable d1 = new BitmapDrawable(circleBitmap); Drawable d2 = login.this.getResources().getDrawabl ...

  7. leetcode 【 Triangle 】python 实现

    题目: Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjace ...

  8. 线段树&树状数组模板

    树状数组: #include <bits/stdc++.h> using namespace std; ; struct binit { int a[MAXN], n; void modi ...

  9. Leetcode 655.输出二叉树

    输出二叉树 在一个 m*n 的二维字符串数组中输出二叉树,并遵守以下规则: 行数 m 应当等于给定二叉树的高度. 列数 n 应当总是奇数. 根节点的值(以字符串格式给出)应当放在可放置的第一行正中间. ...

  10. 直接插入排序(java实现)

    这几天看排序算法,网上大多数排序算法的解释都是“过于专业”,导致一时半会看不明白到底在说什么玩意.现在总结下几大排序算法(java实现) 1.直接插入排序 说的简单点,就是一组无序序列{A1,A2,. ...