Adjacent Bit Counts
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 599   Accepted: 502

Description

For a string of n bits x1, x2, x3, …, xn, the adjacent bit count of the string (AdjBC(x)) is given by

x1*x2 + x2*x3 + x3*x4 + … + xn-1*xn

which counts the number of times a 1 bit is adjacent to another 1 bit. For example:

AdjBC(011101101) = 3 
AdjBC(111101101) = 4 
AdjBC(010101010) = 0

Write a program which takes as input integers n and k and returns the number of bit strings x of n bits (out of 2ⁿ) that satisfy AdjBC(x) = k. For example, for 5 bit strings, there are 6 ways of getting AdjBC(x) = 2:

11100, 01110, 00111, 10111, 11101, 11011

Input

The first line of input contains a single integer P, (1 ≤ P ≤ 1000), which is the number of data sets that follow. Each data set is a single line that contains the data set number, followed by a space, followed by a decimal integer giving the number (n) of bits in the bit strings, followed by a single space, followed by a decimal integer (k) giving the desired adjacent bit count. The number of bits (n) will not be greater than 100 and the parameters n and k will be chosen so that the result will fit in a signed 32-bit integer.

Output

For each data set there is one line of output. It contains the data set number followed by a single space, followed by the number of n-bit strings with adjacent bit count equal to k.

Sample Input

10
1 5 2
2 20 8
3 30 17
4 40 24
5 50 37
6 60 52
7 70 59
8 80 73
9 90 84
10 100 90

Sample Output

1 6
2 63426
3 1861225
4 168212501
5 44874764
6 160916
7 22937308
8 99167
9 15476
10 23076518

Source

 
  1. 由0,1组成的长度为n的数列x1,x2,x3,x4.....xn,定义一个操作为
  2. AdjBC(x) = x1*x2 + x2*x3 + x3*x4 + … + xn-1*xn 。
  3. 输入两个数n和m,求长度为n的数列,经过上述操作,最后结果为m共有多少种
  4. 思路 : DP,递推
  5. d[i][j][0]:表示前i项组成和为j且第i项为0共有多少种
  6. d[i][j][1]:表示前i项组成和为j且第i项为1共有多少种
  7. 状态转移方程:
  8. d[i][j][1] = d[i-1][j][0] + d[i-1][j-1][1];
  9. d[i][j][0] = d[i-1][j][1] + d[i-1][j][0]
    #include <stdio.h>
    #include <math.h>
    #include <iostream>
    #include <string.h>
    #include <algorithm>
    #include <queue>
    #define maxn 105
    using namespace std;
    int main()
    {
    int t,n,m;
    int dp[maxn][maxn][];
    dp[][][] = dp[][][] = ;
    for(int i=;i<maxn;i++){
    dp[i][][] = dp[i-][][] + dp[i-][][];
    dp[i][][] = dp[i-][][];
    }
    for(int i=;i<maxn;i++){
    for(int j=;j<maxn;j++){
    dp[i][j][] = dp[i-][j][] + dp[i-][j][];
    dp[i][j][] = dp[i-][j][] + dp[i-][j-][];
    }
    }
    int T;
    cin >> T;
    while(T--){
    cin >> t >> n >> m;
    cout << t << " " << dp[n][m][]+dp[n][m][] << endl;
    }
    return ;
    }

POJ 3786 dp-递推 Adjacent Bit Counts *的更多相关文章

  1. hdu2089(数位DP 递推形式)

    不要62 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  2. HOJ 2148&POJ 2680(DP递推,加大数运算)

    Computer Transformation Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4561 Accepted: 17 ...

  3. poj 2506 Tiling 递推

    题目链接: http://poj.org/problem?id=2506 题目描述: 有2*1和2*2两种瓷片,问铺成2*n的图形有多少种方法? 解题思路: 利用递推思想,2*n可以由2*(n-1)的 ...

  4. hdu 2604 Queuing(dp递推)

    昨晚搞的第二道矩阵快速幂,一开始我还想直接套个矩阵上去(原谅哥模板题做多了),后来看清楚题意后觉得有点像之前做的数位dp的水题,于是就用数位dp的方法去分析,推了好一会总算推出它的递推关系式了(还是菜 ...

  5. Power oj2498/DP/递推

    power oj 2498 /递推 2498: 新年礼物 Time Limit: 1000 MS Memory Limit: 65536 KBTotal Submit: 12 Accepted: 3  ...

  6. BZOJ4321queue2——DP/递推

    题目描述 n 个沙茶,被编号 1~n.排完队之后,每个沙茶希望,自己的相邻的两 人只要无一个人的编号和自己的编号相差为 1(+1 或-1)就行:  现在想知道,存在多少方案满足沙茶们如此不苛刻的条件. ...

  7. Shell Necklace (dp递推改cdq分治 + fft)

    首先读出题意,然后发现这是一道DP,我们可以获得递推式为 然后就知道,不行啊,时间复杂度为O(n2),然后又可以根据递推式看出这里面可以拆解成多项式乘法,但是即使用了fft,我们还需要做n次多项式乘法 ...

  8. hdu 1723 DP/递推

    题意:有一队人(人数 ≥ 1),开头一个人要将消息传到末尾一个人那里,规定每次最多可以向后传n个人,问共有多少种传达方式. 这道题我刚拿到手没有想过 DP ,我觉得这样传消息其实很像 Fibonacc ...

  9. UVA 10559 Blocks(区间DP&&递推)

    题目大意:给你玩一个一维版的消灭星星,得分是当前消去的区间的长度的平方,求最大得分. 现在分析一下题目 因为得分是长度的平方,不能直接累加,所以在计算得分时需要考虑前一个状态所消去的长度,仅用dp[l ...

随机推荐

  1. H3C软件开发笔试面试总结

    注:我目前是陕西师范大学计算机科学学院本科生,在西安参加笔试以及面试 先是笔试,我选择的是JAVA方向,笔试选择题目主要是一些基础性的题目,然后简答题问了final.finally.finallize ...

  2. DesignPattern系列__04里氏替换原则

    1.内容引入--继承体系的思考 在继承中,凡是在父类已经实现的方法,其实算是一种契约或者规范,子类不应该在进行更改(重写):但是,由于这一点不是强制要求,所以当子类进行重写的时候,就会对继承体系产生破 ...

  3. Git命令备忘录

    目录 前言 基本内容 开始之前 基础内容 远程仓库 分支管理 前言 Git在平时的开发中经常使用,整理Git使用全面的梳理. 基本内容 开始之前 请自行准备好Git工具以及配置好Git的基本配置 基础 ...

  4. 不用 Spring Security 可否?试试这个小而美的安全框架

    写在前面 在一款应用的整个生命周期,我们都会谈及该应用的数据安全问题.用户的合法性与数据的可见性是数据安全中非常重要的一部分.但是,一方面,不同的应用对于数据的合法性和可见性要求的维度与粒度都有所区别 ...

  5. MariaDB 修改存储路径后启动失败问题解决

    修改 MariaDB 路径到 home 路径下, 执行 systemctl start mariadb 启动MariaDB 时,报错提示: Job for mariadb.service failed ...

  6. React-Native之打包发布(Android)

    React-Native之打包发布(Android) 一,介绍与需求 移动端打包发布到应用市场 二,发布配置 注意:以下所有操作都在win10下进行,React Native版本0.59.5,andr ...

  7. jq css3实现跑马灯+大转盘

    前端效果, <!DOCTYPE HTML><html><head> <meta http-equiv="Content-Type" con ...

  8. Docker 核心技术

    docker是什么?为什么会出现? 容器虚拟化技术:轻量级的虚拟机(但不是虚拟机) 开发:提交代码 ——> 运维:部署 在这中间,因为环境和配置,出现问题 ——> 把代码/配置/系统/数据 ...

  9. 百度Echarts,蚂蚁金服G2,D3三种主流可视化工具对比

    1.百度的Echarts 官网:https://echarts.baidu.com/ 介绍:ECharts,缩写来自Enterprise Charts,是百度推出的一款开源的,商业级数据图表,它最初是 ...

  10. Navicat连接MYsql报错

    在Windows中安装mysql8后,使用Navicat连接数据库是出现“ Client does not support authentication protocol requested by s ...