1 条题解
-
0
题目描述
一首诗(或一首较长诗歌中的一个诗节)的韵律模式表明了这首诗中哪些行与其他哪些行押韵。例如,像下面这样的一首五行打油诗: “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” 作者是詹妮弗和彼得·肖尔(http://www.research.att.com/~shor/notapoet.html) 它的韵律模式是“aabba”,这表示第一行、第二行和第五行押韵,第三行和第四行押韵。
对于一首有四行的诗或诗节,有 15 种可能的韵律模式: “aaaa, aaab, aaba, aabb, aabc, abaa, abab, abac, abba, abbb, abbc, abca, a bcb, abcc, 以及 abcd”。
编写一个程序,计算当输入值为 N 时,一首有 N 行的诗或诗节的韵律模式的数量。
输入
输入将由一系列整数 N 组成,每行一个,以一个 0(零)表示数据的结束。N 是一首诗的行数。
输出
对于每个输入整数 N,你的程序应该输出 N 的值,后面跟一个空格,再后面跟一个以十进制整数形式表示的有 N 行的诗的韵律模式的数量,该整数至少有 12 位正确的有效数字(在计算中使用双精度浮点数)。
输入数据 1
1 2 3 4 20 30 10 0
输出数据 1
1 1 2 2 3 5 4 15 20 51724158235372 30 846749014511809120000000 10 115975
题目来源
大纽约地区 2003 年竞赛
C++实现
#include <iostream> #include <cstring> #include <queue> #include <vector> #include <algorithm> #include <cstdio> #include <set> #include <map> #include <stack> //#include <tr1/unordered_map> //#include <unordered_map> #include <cmath> //#include<bits/stdc++.h> using namespace std; #define sfi(i) scanf("%d",&i) #define sfl(i) scanf("%I64d",&i) #define sfs(i) scanf("%s",(i)) #define pri(i) printf("%d\n",i) #define prl(i) printf("%I64d\n",i) #define sff(i) scanf("%lf",&i) #define ll long long #define ull unsigned long long #define uint unsigned int #define mem(x,y) memset(x,y,sizeof(x)) #define INF 0x3f3f3f3f #define inf 1e18 #define eps 1e-10 #define PI acos(-1.0) #define lowbit(x) ((x)&(-x)) #define fl() printf("flag\n") #define MOD(x) ((x%mod)+mod)%mod #define endl '\n' #define pb push_back #define lson (rt<<1) #define rson (rt<<1|1) #define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0) template<typename T>inline void read(T &x) { x=0; static int p;p=1; static char c;c=getchar(); while(!isdigit(c)){if(c=='-')p=-1;c=getchar();} while(isdigit(c)) {x=(x<<1)+(x<<3)+(c-48);c=getchar();} x*=p; } //----------------------------------------------- const int maxn=1e2+9; const int maxm=3e6+9; const int mod=20090126; double s[maxn][maxn]; int main() { //FAST_IO; //freopen("input.txt","r",stdin); s[1][0]=0; s[1][1]=1; for(int i=2;i<=100;i++) { for(int j=1;j<=i;j++) { s[i][j]=(s[i-1][j]*(j)+s[i-1][j-1]); } } int n; while(~scanf("%d",&n)&&n) { double ans=0; for(int i=1;i<=n;i++) { ans=ans+s[n][i]; } printf("%d %.0f\n",n,ans); } return 0; }
- 1
信息
- ID
- 672
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 10
- 标签
- 递交数
- 2
- 已通过
- 1
- 上传者