Computer Transformation

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7210    Accepted Submission(s): 2628

Problem 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 consecutive zeroes pairs that will appear in the sequence after n steps.
 
Sample Input
2
3
 
Sample Output
1
1
 
Source
 
题意:给定初始值1,然后进行变换,变换的规则是 1->01 ,0->10,问进行n次变换后串中00的个数。
 
题解:
写出前几项:
              1
             01         第1次(项)
           1       第2次(项)
       101001    第3次 (项)
01101001    第4次(项)
....
我们会发现只有当串中存在1001时会出现00

而要出现1001,则父串中要出现01

父串中出现01串有两种方法,一种是我所标注的红色部分,由祖父串中的1变过来

第二种方式就是当祖父串中有00时 父串变成 1010 时会出现 01

所以这样就可以得到递推公式:第n项00的个数 = 第 n-2项 1的个数+第n-2项 00 的个数。

f[1] = 0

f[2] = 1

f[n] = f[n-2]+2^(n-3)  ( n>2 )

import java.math.BigInteger;
import java.util.Scanner; public class Main {
public static void main(String[] args) {
BigInteger [] h = new BigInteger[1001];
h[1] = new BigInteger("0");
h[2] = new BigInteger("1");
for(int i=3;i<=1000;i++){
h[i] = h[i-2].add(pow(i-3));
}
Scanner sc =new Scanner (System.in);
while(sc.hasNext()){
int n =sc.nextInt();
System.out.println(h[n]);
}
} private static BigInteger pow(int v) {
BigInteger sum = BigInteger.valueOf(1);
for(int i=0;i<v;i++){
sum = sum.multiply(BigInteger.valueOf(2));
}
//System.out.println(sum);
return sum;
}
}

hdu 1041(递推,大数)的更多相关文章

  1. Children’s Queue HDU 1297 递推+大数

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1297 题目大意: 有n个同学, 站成一排, 要求 女生最少是两个站在一起, 问有多少种排列方式. 题 ...

  2. Buy the Ticket HDU 1133 递推+大数

    题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=1133 题目大意: 有m+n个人去买电影票,每张电影票50元,  m个人是只有50元一张的,  n个人 ...

  3. HDOJ(HDU).2044-2049 递推专题

    HDOJ(HDU).2044-2049 递推专题 点我挑战题目 HDU.2044 题意分析 先考虑递推关系:从1到第n个格子的时候由多少种走法? 如图,当n为下方格子的时候,由于只能向右走,所以有2中 ...

  4. HDU 2842 (递推+矩阵快速幂)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2842 题目大意:棒子上套环.第i个环能拿下的条件是:第i-1个环在棒子上,前i-2个环不在棒子上.每个 ...

  5. Tiling(递推+大数)

    Description In how many ways can you tile a 2xn rectangle by 2x1 or 2x2 tiles? Here is a sample tili ...

  6. "红色病毒"问题 HDU 2065 递推+找循环节

    题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=2065 递推类题目, 可以考虑用数学方法来做, 但是明显也可以有递推思维来理解. 递推的话基本就是状态 ...

  7. 【hdoj_1865】1sting(递推+大数)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1865 本题的关键是找递推关系式,由题目,可知前几个序列的结果,序列长度为n=1,2,3,4,5的结果分别是 ...

  8. hdu 2044-2050 递推专题

    总结一下做递推题的经验,一般都开成long long (别看项数少,随便就超了) 一般从第 i 项开始推其与前面项的关系(动态规划也是这样),而不是从第i 项推其与后面的项的关系. hdu2044:h ...

  9. ACM学习历程—HDU1041 Computer Transformation(递推 && 大数)

    Description A sequence consisting of one digit, the number 1 is initially written into a computer. A ...

随机推荐

  1. Redis、Memcache

    ★ Redis redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(sor ...

  2. 直通BAT面试算法精讲课 --动态规划

    1.有数组penny,penny中所有的值都为正数且不重复.每个值代表一种面值的货币,每种面值的货币可以使用任意张,再给定一个整数aim(小于等于1000)代表要找的钱数,求换钱有多少种方法. 给定数 ...

  3. 如何使用impdp导入oracle数据库文件

    1.首先,安装好oracle数据库. 2.使用sqlplus进入sysdba权限,sqlplus "/as sysdba", 例如: 3.创建用户framework,例如: CRE ...

  4. BST POJ - 2309 思维题

    Consider an infinite full binary search tree (see the figure below), the numbers in the nodes are 1, ...

  5. Generating Sets 贪心

    H - Generating Sets Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64 ...

  6. 基于jQuery UI的调色板插件推荐colorpicker

    1.下载地址 点击网页最下端Download,即可下载 2.使用方法 本插件是基于jQuery UI,所以应该先行下载jQuery UI,当然jQuery也必不可少 引入和初始化   引入js文件 & ...

  7. select + 回调 + 事件循环

    #1. epoll并不代表一定比select好 # 在并发高的情况下,连接活跃度不是很高, epoll比select # 并发性不高,同时连接很活跃, select比epoll好 #通过非阻塞io实现 ...

  8. Jmeter-6-创建数据库测试计划

    1. 将mysql 的jdbc的jar包放到Jmeter lib的目录下. 2. 创建线程组. 3. 创建JDBC Connection Configuration, 提供详细的数据库配置信息. 4. ...

  9. 【GDKOI2016Day1T1-魔卡少女】【拆位】线段树维护区间内所有连续子区间的异或和

    题意:给出N个数,M个操作.操作有修改和询问两种,每次修改将一个数改成另一个数,每次询问一个区间的所有连续子区间的异或和.n,m<=100000,ai<=1000 题解: 当年(其实也就是 ...

  10. 【BZOJ】1709: [Usaco2007 Oct]Super Paintball超级弹珠

    [算法]模拟 [题解]O(n^2)预处理横线(y),纵线(x),主对角线(y-x+n),副对角线(x+y). 然后n^2枚举每个点.