Time Limit:1000MS Memory Limit:16384KTotal Submit:29 Accepted:13 Description 背景 "如果两个人相差一秒出生, 其中一个是小孩, 那么另一个也是小孩. 由此可以推论, 所有人均是小孩." 问题 数计系是一个由N个人组成的大家庭, 分别为1, 2, 3, ..., N岁. 有一次系主任想为全系拍张合照. 需要所有学生站成一排. 起先他想按他们的岁数从小到大安排, 但后来又觉得这样不自然. 于是他建议按如下方案站排: 1岁的在最左边. 每相邻两人不得相差超过2岁. 这样学生的岁数看起来显得很平均(25岁和27岁的人差别很难看出). 存在多种方案满足此要求. 摄影师不想违反系主任的意愿, 就为每种可能的安排分别拍了一张照片. Input 整数N, 1<=N<=55. Output 所拍照片张数. Sample Input 4 Sample Output 4 Hint 若N=4, 则有4种可能的安排: (1,2,3,4), (1,2,4,3), (1,3,2,4) and (1,3,4,2). Source Open collegiate programming contest for high school children of the Sverdlovsk region, October 11, 2 #include<stdio.h> int main() { int i,n; int tog,tog_1,tog_2,tog_12_1,temp; long f[58]; tog=1; tog_1=1; tog_2=0; tog_12_1=1; f[1]=1; f[2]=1; for(i=3;i<=55;i++) { f[i]=tog+tog_1+tog_2; temp=tog_12_1; tog_12_1=tog_1; tog=f[i]-tog_2; tog_1=tog_1+tog_2; tog_2=temp; } scanf("%d",&n); printf("%ld\n",f[n]); return 0; }

评论