ZOJ 2771
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.

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的更多相关文章
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- ZOJ Problem Set - 1394 Polar Explorer
这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...
- ZOJ Problem Set - 1392 The Hardest Problem Ever
放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...
- ZOJ Problem Set - 1049 I Think I Need a Houseboat
这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...
- ZOJ Problem Set - 1006 Do the Untwist
今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ...
- ZOJ Problem Set - 1001 A + B Problem
ZOJ ACM题集,编译环境VC6.0 #include <stdio.h> int main() { int a,b; while(scanf("%d%d",& ...
- zoj 1788 Quad Trees
zoj 1788 先输入初始化MAP ,然后要根据MAP 建立一个四分树,自下而上建立,先建立完整的一棵树,然后根据四个相邻的格 值相同则进行合并,(这又是递归的伟大),逐次向上递归 四分树建立完后, ...
随机推荐
- 【Alpha】Daily Scrum Meeting第十次
一.本次Daily Scrum Meeting主要内容 每个人学习情况 测试的任务的安排 Alpha版本展示的具体内容 二.任务安排 学号尾数 昨天做的任务 今天做的任务 任务用时 612 完成将计时 ...
- Linux串口中的超时设置
在Linux下使用串口通信时,默认的阻塞模式是不实用的.而采用select或epoll机制的非阻塞模式,写代码有比较麻烦.幸好Linux的串口自己就带有超时机制. Linux下使用termios.h中 ...
- GCC 编译优化指南(转)
GCC 编译优化指南(转) http://www.jinbuguo.com/linux/optimize_guide.html 作者:金步国 版权声明 本文作者是一位开源理念的坚定支持者,所以本文虽然 ...
- java1
1:计算机概述(了解) (1)计算机 (2)计算机硬件 (3)计算机软件 系统软件:window,linux,mac 应用软件:qq,yy,飞秋 (4)软件开发(理解) 软件:是由数据和指令组成的.( ...
- 在react native用到的javascript 的一些关键知识(整理中)
发现了一个讲解javascript的好网站,分享一下,讲的非常棒! 注意,这些文章都可以选择中文进行阅读! 下面这个连接是关于prototype的: https://developer.mozilla ...
- OC编程之道-创建对象之单例模式
一 何为单例singleton模式?(what) 保证一个类只有一个实例,并提供一个访问它的全局访问点. 二 何时使用单例模式?(where) 1类只能有一个实例,而且必须从一个为人熟知的访问点对其访 ...
- Oracle生成指定表的列名,并前后添加select from
表的列名比较多的时候,手工一个个的写列名比较麻烦,这个函数可以让人偷偷懒 create or replace function f_GetCols(p_TableName in varchar2/*获 ...
- 使用原生ajax处理json组成的数组
和前一篇文章一样,直接上代码了,只是做个记录. 数据的提供页面,tigong.php <?php header("content-type:text/html;charset=utf- ...
- JS Date
JS获取当前日期时间 var myDate = new Date();myDate.getFullYear(); //获取完整的年份(4位,1970-????)myDate.getMonth() ...
- HBASE列族不能太多的真相 (一个table有几个列族就有几个 Store)
HRegionServer内部管理了一系列HRegion对象,每个HRegion对 应了table中的一个region,HRegion中由多 个HStore组成.每个HStore对应了Table中的一 ...