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 建立一个四分树,自下而上建立,先建立完整的一棵树,然后根据四个相邻的格 值相同则进行合并,(这又是递归的伟大),逐次向上递归 四分树建立完后, ...
随机推荐
- java基础知识(一)数据类型(下)
前面介绍了java的8种基本数据类型,包括boolean, byte, char, short, int, long, float, double.同时,java也提供了这些类型的封装类,分别为Bo ...
- Java 23种设计模式 (通俗易懂解释收集整理)
(补充中...) P02 抽象工程模式 P14 TemplateMethod 模板方法模式 讲清楚了为什么叫做模板方法 http://www.cnblogs.com/java-my-life/arc ...
- ToolStripMenuItem
MenuStrip 类 为窗体提供菜单系统. 继承层次结构 System.Object System.MarshalByRefObject System.ComponentModel.Comp ...
- WCF service 获取 client 端的 IP 和 port (转)
转帖记录一下,以便日后使用. 主要使用是.NET3.5里的服务端上下文的消息实例的RemoteEndpointMessageProperty属性,获取客户端地址信息.但是限制 的绑定是HTTP.TCP ...
- [Linux]系统调用理解(3)
本文介绍了Linux下的进程的一些概念,并着重讲解了与Linux进程管理相关的重要系统调用wait,waitpid和exec函数族,辅助一些例程说明了它们的特点和使用方法. 1.7 背景 在前面的文章 ...
- vbox中虚拟ubuntu增加新的虚拟硬盘
vbox中虚拟ubuntu增加新的虚拟硬盘 在virtualbox中装好Ubuntu后,发现硬盘空间不够使用 了.以下是搜集整理的解决办法: 1. 添加新硬盘 设置 -> ...
- Android 小笔记
<!-- xml --> android:visibility="gone" 可以隐藏 元素 xmlns:bootstrapbu ...
- iOS开发UI篇—核心动画(关键帧动画)
转自:http://www.cnblogs.com/wendingding/p/3801330.html iOS开发UI篇—核心动画(关键帧动画) 一.简单介绍 是CApropertyAnimatio ...
- MySQL 编译安装并且开启DEBUG模式
因为想分析下mysql中一些操作的内部执行过程,单纯的看源码太枯燥了,所以决定结合mysql的执行过程来分析,mysql作为一款成熟的数据库软件,在设计的时候就考虑到了调试的问题,只是想开启调试模式的 ...
- angularjs---select使用---默认值及联动
angularjs---select使用---默认值及联动 代码 一. select设置默认显示内容&&获取下拉框显示内容. HTML <div> <select ...