HOJ 2148&POJ 2680(DP递推,加大数运算)
来源:互联网 发布:成都网络推广公司电话 编辑:程序博客网 时间:2024/05/21 12:44
Computer Transformation
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 4561 Accepted: 1738
Description
A sequence consisting of one digit, the number 1 is initially written into a computer. At each successive time step, the computer simultaneously tranforms each digit 0 into the sequence 1 0 and each digit 1 into the sequence 0 1. So, after the first time step, the sequence 0 1 is obtained; after the second, the sequence 1 0 0 1, after the third, the sequence 0 1 1 0 1 0 0 1 and so on.
How many pairs of consequitive zeroes will appear in the sequence after n steps?
Input
Every input line contains one natural number n (0 < n <= 1000).
Output
For each input n print the number of consequitive zeroes pairs that will appear in the sequence after n steps.
Sample Input
2
3
Sample Output
1
1
Source
这是我第一次用java进行大数运算
递推很简单,00只可能是上一个的01产生,上一个的01只可能是上上一个的00 1产生
hoj的测试机好像有问题,poj里面ac的代码提交不上去hoj
import java.math.BigInteger;import java.util.Scanner;/** * * @author chenyongkang */public class Main { public static BigInteger a; public static BigInteger b[]=new BigInteger[1010]; public static void init() { BigInteger x=BigInteger.valueOf(0); BigInteger y=BigInteger.valueOf(1); for(int i=0;i<=1000;i++) b[i]=BigInteger.valueOf(0); b[1]=x;b[2]=y; for(int i=3;i<=1000;i++) { a=BigInteger.valueOf(1); for(int j=1;j<=i-3;j++) { a=a.multiply(BigInteger.valueOf(2)); } b[i]=b[i].add(b[i-2]); b[i]=b[i].add(a); } } /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here init(); Scanner cin=new Scanner(System.in); while(cin.hasNext()) { int n=cin.nextInt(); System.out.println(b[n]); } }}
- HOJ 2148&POJ 2680(DP递推,加大数运算)
- ACM--递推加大数--HDOJ 1865--1string--水
- poj 1837 dp推方案数
- POJ 2229 Sumsets(dp 递推)
- POJ——2506(找规律加大数乘法 )
- POJ 3298 递推,DP
- 2016百度之星 资格赛 1002 Problem B 递推加大数
- HDU 1502 三维dp加大数
- POJ-2506--Tiling (递推+大数运算)
- HD 2048 数塔 DP(简单递推)
- HDU 2084 数塔 (DP递推)
- [poj 3254] Corn Fields 状态压缩DP(递推)
- 【POJ 2663】Tri Tiling(dp|递推)
- [状态压缩DP/递推/位运算] Pku/Poj Corn Fields 状态DP入门题详细注释。
- poj Chocolate dp递推+精度问题
- poj 2506 Tiling dp 递推
- 【poj 3176】 Cow Bowling 递推dp
- poj 3597 Polygon Division(dp递推)
- Leetcode:BinaryTree level order Traversal and Zigzag traversal
- HDU 2544 最短路 (弗洛伊德模板)
- HDU 1280 前m大的数
- c++字符串与数值之间的转换
- mac os上安装mongoldb
- HOJ 2148&POJ 2680(DP递推,加大数运算)
- inline和define
- 在Spring中配置使用commons-logging的simplelog来输出日志
- 简单的事情复杂做
- 深入理解Android消息处理系统——Looper、Handler、Thread
- 关于FSM(有限状态机)的学习2
- SQL注入与防范
- 手机卫士第七天笔记
- 在web service间传递java bean