POJ 1671 Rhyme Schemes

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.


【题目分析】
看到了题目样例输出,蒙蔽+高精?但是它有sj,只需要用float就可以混精度了。然后就是Stirling数的递推了。行数>=韵律数,就是n行放进k个韵律的组合情况所以每读进来一个数,只需要累加一下再输出就可以了。


【代码】

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
double f[101][101];
int n;
int main()
{
    for (int i=2;i<=100;++i) f[1][i]=0;
    for (int i=1;i<=100;++i) f[i][1]=1;
    for (int i=2;i<=100;++i)
        for (int j=2;j<=i;++j)
            f[i][j]=f[i-1][j-1]+f[i-1][j]*j;
    while (scanf("%d",&n)==1&&n)
    {
        double ret=0;
        for (int i=1;i<=n;++i) ret+=f[n][i];
        printf("%d %.0lf\n",n,ret);
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值