博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HOJ 2148&POJ 2680(DP递推,加大数运算)
阅读量:4676 次
发布时间:2019-06-09

本文共 1959 字,大约阅读时间需要 6 分钟。

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]); } }}

转载于:https://www.cnblogs.com/dacc123/p/8228791.html

你可能感兴趣的文章
【模板题】欧拉回路
查看>>
QEMU+GDB调试方法
查看>>
洛谷 P1272 重建道路(树形DP)
查看>>
sql
查看>>
ShellExecute与ShellExecuteEx的用法
查看>>
第16课 “远程 Git文档库” 的基础操作
查看>>
总结oninput、onchange与onpropertychange事件的使用方法和差别
查看>>
go语言的特点
查看>>
leetcode : Remove Duplicates from Sorted List II [基础]
查看>>
常用正则汇集
查看>>
关于小范围整数N拆解成2的幂相加的个数
查看>>
基于visual Studio2013解决C语言竞赛题之1044数组处理
查看>>
省份封装代码
查看>>
中缀表达式-后缀表达式M
查看>>
Linux基础命令
查看>>
cat和cp的神奇用法:制作U盘安装盘
查看>>
JNI调用两层C++动态库
查看>>
状态压缩动态规划 - 总结【普及+,提高-】
查看>>
Git pull 强制覆盖本地文件
查看>>
android preferenceActivity的用法
查看>>