ZOJ 2771 Get Out of the Glass 很普通的计数dp
2015-07-15 20:54
393 查看
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2771
Get Out of the Glass
Time Limit: 2 Seconds
Memory Limit: 65536 KB
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:
Sample Output:
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.
题意:
玻璃一共有3层
从上方射入玻璃后(不能在最上面直接反射出去,必须先进入玻璃),问n次折射的走法有多少种。
dp[i][j]
i代表第几次折射 奇偶可以判断向上走还是向下。
j代表当前在第几层。
虽然c++也能过 但是其实会爆 llu的。
Get Out of the Glass
Time Limit: 2 Seconds
Memory Limit: 65536 KB
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.
题意:
玻璃一共有3层
从上方射入玻璃后(不能在最上面直接反射出去,必须先进入玻璃),问n次折射的走法有多少种。
dp[i][j]
i代表第几次折射 奇偶可以判断向上走还是向下。
j代表当前在第几层。
虽然c++也能过 但是其实会爆 llu的。
import java.util.Scanner; import java.math.*; import java.text.*; public class Main { public static void main(String[] args) { Scanner cin=new Scanner(System.in); BigInteger []f = new BigInteger[1010]; BigInteger ans; BigInteger[][] dp=new BigInteger[70][4]; BigInteger li=BigInteger.ZERO; BigInteger yi=BigInteger.ONE; while(cin.hasNext()) { int n; n=cin.nextInt(); for(int i=0;i<=n;i+=1) { for(int j=0;j<4;j+=1) { dp[i][j]=li; } } dp[0][0]=yi; ans=li; for(int i=0;i<n;i+=1) { for(int j=0;j<4;j+=1) { if(i%2==1) { for(int l=0;l<j;l++) dp[i+1][l]=dp[i+1][l].add(dp[i][j]); } else { for(int l=j+1;l<4;l++) { dp[i+1][l]=dp[i+1][l].add(dp[i][j]); } } } } for(int j=0;j<4;j++) { ans=ans.add(dp [j]); } System.out.println(ans); } } }
相关文章推荐
- LeetCode从零单排之零分段——Delete Node in a Linked List(删除链表中的元素)
- Android 开发 单选按钮的实现
- 冒泡方排序
- Windows下运行Vmware产生的vmnat.exe占用CPU过高问题
- 学习资源
- 黑马程序员-C语言基础二:数据类型、常量、变量
- GCD dispatch async / dispatch sync 介绍 。
- Mac生存手册
- 字符串MD5加密运算
- Codeforces 558B Amr and The Large Array
- DT大数据梦工厂 第53讲
- android官方教程学习01——ActionBar1
- 层次遍历二叉树—vector的彪悍与神秘
- ES6 详解二: 新增内容概览
- opencv例程说明
- oracle怎么把系统时间与某个时间的差值与另一个数值进行比较
- hdu 1181 变形课
- 基于事件的隐式调用风格
- POJ 1258 Agri-Net //Prim算法
- 静态文件服务器(The static file servers)