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的更多相关文章

  1. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  2. ZOJ People Counting

    第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ  3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...

  3. ZOJ 3686 A Simple Tree Problem

    A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each no ...

  4. ZOJ Problem Set - 1394 Polar Explorer

    这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...

  5. ZOJ Problem Set - 1392 The Hardest Problem Ever

    放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...

  6. ZOJ Problem Set - 1049 I Think I Need a Houseboat

    这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...

  7. ZOJ Problem Set - 1006 Do the Untwist

    今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ...

  8. ZOJ Problem Set - 1001 A + B Problem

    ZOJ ACM题集,编译环境VC6.0 #include <stdio.h> int main() { int a,b; while(scanf("%d%d",& ...

  9. zoj 1788 Quad Trees

    zoj 1788 先输入初始化MAP ,然后要根据MAP 建立一个四分树,自下而上建立,先建立完整的一棵树,然后根据四个相邻的格 值相同则进行合并,(这又是递归的伟大),逐次向上递归 四分树建立完后, ...

随机推荐

  1. Alpha总结

    一.预期计划 1.时间:11月7日--11月17日 2.小组分工 角色:程序员.美工.文档.测试 这个阶段以编码为主,每个组员参与编码,同时各自根据自己擅长的方面主要负责一个部分. 项目编码工作分工: ...

  2. kxbdSuperMarquee.js滚动的神器-推荐

    http://code.ciaoca.com/jquery/kxbdmarquee/ 版本:jQuery v1.3.2+ 查看 Demo 下载 jQuery kxbdMarquee 文档目录 使用方法 ...

  3. iOS开发——高级篇——iPad开发、iPad开发中的modal

    一.iPad简介 1.什么是iPad一款苹果公司于2010年发布的平板电脑定位介于苹果的智能手机iPhone和笔记本电脑产品之间跟iPhone一样,搭载的是iOS操作系统 2.iPhone和iPadi ...

  4. javascript基础01

    javascript基础01 Javascript能做些什么? 给予页面灵魂,让页面可以动起来,包括动态的数据,动态的标签,动态的样式等等. 如实现到轮播图.拖拽.放大镜等,而动态的数据就好比不像没有 ...

  5. PDO 用法学习

    PDO: php data object数据库访问抽象层 基于驱动:1.安装扩展 php_pdo.dll2.安装驱动 php_pdo_mysql.dll linux 编译时参数:--with-pdo= ...

  6. delphi XE4 隐藏程序在任务管理器和隐藏任务栏

    最新处理方法,偶然发现delphi下有个ShowMainForm属性,只要在Application.Initialize;后面加上Application.ShowMainForm := false;就 ...

  7. 外网通过root账户访问虚拟机mysql

    http://www.cnblogs.com/live41/archive/2013/04/02/2995178.html

  8. SQLServer2008设置 开启远程连接

    SQLServer2008设置 开启远程连接 前一段时间,学生分组做项目,使用SVN工具,要求功能使用存储过程,在数据库这块出现这么一个问题: A学生在他的数据库上添加了存储过程,需要其他的B,C,D ...

  9. URL类型入参串调用接口

    最近通过调用另一个合作公司提供的接口实现方法,借鉴同事之前编写的方法 Models.JSON.Patient类中有各种属性,也可增加属性来满足新需求 public string TakeAppoint ...

  10. Python中使用递归输出嵌套列表并转化为大写