Computer Transformation
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 4548   Accepted: 1731

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
import java.util.*;
import java.math.*; public class Main { public static void main(String[] args) {
final int maxn = 1010;
BigInteger fa[] = new BigInteger[maxn];
BigInteger fb[] = new BigInteger[maxn];
BigInteger TWO = BigInteger.valueOf(2);
fa[0] = fb[0] = BigInteger.ZERO;
for (int i = 1; i < maxn; i ++) {
fa[i] = fa[i-1].add(fb[i-1]);
fb[i] = fa[i-1].add(fb[i-1]).add(BigInteger.valueOf(i).mod(TWO));
}
int n;
Scanner cin = new Scanner(System.in);
while (cin.hasNext()) {
n = cin.nextInt();
System.out.println(fb[n-1]);
}
}
}

Python

import sys
fa = [0] * 1010
fb = [0] * 1010
fa[0] = 0;
fb[0] = 0;
for i in range(1, 1010):
fa[i] = fa[i-1] + fb[i-1]
fb[i] = fa[i-1] + fb[i-1] + i % 2 for line in sys.stdin:
n = int(line)
print(fb[n-1])

POJ2680(动态规划,大数)的更多相关文章

  1. ACM学习历程—HDU 3092 Least common multiple(数论 && 动态规划 && 大数)

    Description Partychen like to do mathematical problems. One day, when he was doing on a least common ...

  2. 洛谷 P1005 动态规划 大数

    Problem Description 帅帅经常跟同学玩一个矩阵取数游戏:对于一个给定的n×m的矩阵,矩阵中的每个元素a(i,j)均为非负整数.游戏规则如下: 1 每次取数时须从每行各取走一个元素,共 ...

  3. NYOJ 541 最强的战斗力

    最强DE 战斗力 时间限制:1000 ms  |  内存限制:65535 KB 难度: 描写叙述 春秋战国时期,赵国地大物博,资源很丰富.人民安居乐业.但很多国家对它虎视眈眈.准备联合起来对赵国发起一 ...

  4. 【解题报告】[动态规划] RQNOJ - PID38 / 串的记数

    原题地址:http://www.rqnoj.cn/problem/38 解题思路: 状态表示:dp[i][j][k]表示i个A,j个B,k个C组成的满足条件的字符串的个数 初始状态:dp[0][0][ ...

  5. NI笔试——大数加法

    NI笔试: 1.找出字符串第一次出现的字符.用数组建立哈希表,然后再扫描字符串并判断次数是否为1. 2.大数加法,即字符串加法.因为之前写过乘法,就以为是乘法.然后就把乘法写上去了····= = 好了 ...

  6. HDU1223 Order Count 动态规划 组合数

    动态规划+组合数+大数 #include<cstdio> #include<cstdlib> #include<iostream> #include<algo ...

  7. soj1166. Computer Transformat(dp + 大数相加)

    1166. Computer Transformat Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description A sequenc ...

  8. 大数问题,通常用JAVA

    e.g. HDU1002 简单加法 import java.math.BigInteger; import java.util.Scanner; public class Main { public ...

  9. [SinGuLaRiTy] 动态规划题目复习

    [SinGuLaRiTy-1026] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. [UVA 1025] A Spy in the Metr ...

随机推荐

  1. 第二篇 Python初识别及变量名定义规范

    第一个Python程序 可以打开notepad或者其他文本编辑器,输入:print("Hello Python!"),将文件保存到任意盘符下,后缀名是  .py 两种python程 ...

  2. 树莓派3_win10下使用"远程桌面连接"与树莓派通信(使用VNC实现连接后)

    -----------------------------------------------------------学无止境------------------------------------- ...

  3. Linux 进程--父进程查询子进程的退出状态

    僵尸进程 当一个子进程先于父进程结束运行时,它与其父进程之间的关联还会保持到父进程也正常地结束运行,或者父进程调用了wait才告终止. 子进程退出时,内核将子进程置为僵尸状态,这个进程称为僵尸进程,它 ...

  4. Failed loading D:\Program Files\phpStudy20161103\php\php-5.6.27-nts\ext\php_xdebug.dll

    我用的是phpstudy 更新完composer php 切换composer的国内源的时候老是报找不到\php_xdebug.dll的错误, 原因是, 在php.ini 里面默写就是在Program ...

  5. HDU 3698 Let the light guide us(DP+线段树)(2010 Asia Fuzhou Regional Contest)

    Description Plain of despair was once an ancient battlefield where those brave spirits had rested in ...

  6. Daily Scrum02 12.04

    第二轮迭代已经进行到了白热化阶段,大家在被编译搞的水深火热的同时依然没有忘记我们的具有颠覆性的团队项目.虽然第一轮迭代我们的成绩不错,但是一定要克服时间不充裕,任务互相冲突的困难,克服不可避免的舆论压 ...

  7. JavaSE复习(七)Stream流和方法引用

    Stream流 全新的Stream概念,用于解决已有集合类库既有的弊端. 传统集合的多步遍历代码 几乎所有的集合(如 Collection 接口或 Map 接口等)都支持直接或间接的遍历操作.而当我们 ...

  8. Python-爬取"我去图书馆"座位编码

    原文地址:http://fanjiajia.cn/2018/11/22/Python-%E7%88%AC%E5%8F%96%E2%80%9D%E6%88%91%E5%8E%BB%E5%9B%BE%E4 ...

  9. java enum naming rules & Pascal case, Camel case, Uppercase

    java enum naming rules Constant & all Capital Case https://stackoverflow.com/questions/3069743/c ...

  10. Python 错误和异常处理

    #常见的异常 class Human: #属性 sex = 'man' age = 18 #方法 def run(self): print('跑啊~~~') #实例化对象 #zw = Human() ...