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 建立一个四分树,自下而上建立,先建立完整的一棵树,然后根据四个相邻的格 值相同则进行合并,(这又是递归的伟大),逐次向上递归 四分树建立完后, ...
随机推荐
- Shell入门教程:流程控制(6)while 循环
while循环的语法: while 条件测试 do 命令区域 done 举例: #!/bin/bash declare -i i=1 declare -i sum=0 while ((i< ...
- Android--UI之Spinner
前言 最近一直在讲AndroidUI的开发,今天讲一下Spinner控件,这是一个列表选择框,可以弹出一个列表供用户选择.在本片博客中,会讲解Spinner的基本属性以及设置之后的效果,以及使用Sim ...
- zTree学习
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- linux 批量kill进程
ps -ef | grep module- | grep -v module-mxm | cut -c 9-15 | xargs kill -9 ps -ef | grep module- 查找关键字 ...
- 理解JavaScript中的作用域和上下文
JavaScript对于作用域(Scope)和上下文(Context)的实现是这门语言的一个非常独到的地方,部分归功于其独特的灵活性. 函数可以接收不同的的上下文和作用域.这些概念为JavaScrip ...
- Delphi DLL的创建、静态及动态调用
转载:http://blog.csdn.net/welcome000yy/article/details/7905463 结合这篇博客:http://www.cnblogs.com/xumenger/ ...
- (一)洞悉linux下的Netfilter&iptables:什么是Netfilter?
转自:http://blog.chinaunix.net/uid-23069658-id-3160506.html 本人研究linux的防火墙系统也有一段时间了,由于近来涉及到的工作比较纷杂,久而久之 ...
- 自动生成V字型
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...
- 全站 HTTPS 来了
!版权声明:本文为腾讯Bugly原创文章,转载请注明出处腾讯Bugly特约作者:刘强 最近大家在使用百度.谷歌或淘宝的时候,是不是注意浏览器左上角已经全部出现了一把绿色锁,这把锁表明该网站已经使用了 ...
- HDU - 3948 后缀数组+Manacher
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3948 题意:给定一个字符串,求字符串本质不同的回文子串个数. 思路:主要参考该篇解题报告 先按照man ...