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 建立一个四分树,自下而上建立,先建立完整的一棵树,然后根据四个相邻的格 值相同则进行合并,(这又是递归的伟大),逐次向上递归 四分树建立完后, ...
随机推荐
- 【转】Entity Framework技术系列之7:LINQ to Entities
前言 LINQ(Language Integrated Query,语言集成查询)是一组用于C#和VB.NET语言的扩展,它允许编写C#或者VB.NET代码,以与查询数据库相同的方式操作内存数据. L ...
- word20161210
gateway / 网关 gateway account / 网关帐户 Gateway Service for NetWare / NetWare 网关服务 GDI objects / GDI 对象 ...
- loadrunner11录制无法打开IE浏览器
安装loadrunner折腾了很久,后来发现是ghost系统问题.重装了系统,再重装了自己需要用的工具~ 接着学习loadrunner,一边看帮助文档一遍学.可是为嘛按照帮助文档的步骤来,就是会碰到一 ...
- ubuntu 创建用户
http://www.jb51.net/article/45848.htm 创建用户
- 出现个Expression(str != NULL)
CPrimerPlus的11章复习题10:编写个函数,其参数为一个字符串指针,返回一个指针,返回的指针指向字符串中第一个空格的位置(如果没有空格就返回空指针) #include <stdio.h ...
- .NET 多线程
多线程 在一个程序中,这些独立运行的程序片断叫作“线程”(Thread),利用它编程的概念就叫作“多线程处理”.多线程处理一个常见的例子就是用户界面.利用线程,用户可按下一个按钮,然后程序会立即作出响 ...
- PHP【函数】
目录:[PHP函数].[PHP数组] 一.PHP常用函数(和JS一样)函数的四要素:①返回类型②函数名③参数类型④函数体因为PHP是弱类型语言,所以可以不用写返回类型,但是其他三个要素都是必须要写的. ...
- eclipse 搭建python环境
1.安装eclipse + jdk windows下面就直接下载,双击安装就完了. Linux下: 安装eclipse: 安装完之后,可直接运行eclipse: 快捷方式在: 安装jidk: 2. ...
- Android:联系人Contacts之ContentResolver query 参数详解
注:本片整理自 http://blog.csdn.net/wssiqi/article/details/8132603 1.获取联系人姓名 一个简单的例子,这个函数获取设备上所有的联系人ID和联系人N ...
- Pyqt 国际化多语言支持
国际化是指在代码设计上加入能方便的移植到其他国家和地区的特性, 给Pyqt 添加国际化支持需要五步 一.编写GUI.py 在要被翻译的text上用tr方法括起来 # -*- coding: utf-8 ...