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