首页 > 其他 > 详细

ZOJ 2771

时间:2014-07-17 12:57:12      阅读:337      评论:0      收藏:0      [点我收藏+]

 

Description

Considering a light entering three adjacent planes of glass.

At any meeting surface, the light may either reflect or continue straight through. For example, here is the light bouncing five times before it leaves the glass.

bubuko.com,布布扣

Given the times the light bounces before leaving the glass, you are asked to tell how many different paths the light can take before leaving the glass.

Input:

Input contains serverl test cases, each test case contains only one integer n (0 <= n <= 60) indicates how many bounces the light take.

Output:

Output how many different paths the light can take.

Sample Input:

 

0
1

 

Sample Output:

 

1
3

 

Hint:

n = 0, the light leave the glass without any bounces, it go straight through the glass.

n = 1, there are three ways for the light to travel with one bounce--bounce at the middle two meeting faces plus the bottom one.



//关键点在于求出数列的递归式子,这道题吧,其实可以用dp做,这个公式可以由dfs推出来
#include <stdio.h> long long a[70]={1,3,6}; int main() { int i,j,N; while(scanf("%d",&N)!=EOF) { for(i=0;i<=N;i++) if(i>2) { a[i]=a[i-1]+a[i-2]; for(j=i-2;j>=0;j--) a[i]+=a[j]; a[i]+=1; } printf("%lld\n",a[N]); } return 0; }

ZOJ 2771,布布扣,bubuko.com

ZOJ 2771

原文:http://www.cnblogs.com/woaixiaduoduo123/p/3850266.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!