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. 在 alpine 中使用 NPOI

    在 alpine 中使用 NPOI Intro 在 .net 中常使用 NPOI 来做 Excel 的导入导出,NPOI 从 2.4.0 版本开始支持 .netstandard2.0,对于.net c ...

  2. 搭建nexus私服

    一.安装 1.从网上下载nexus软件https://www.sonatype.com/download-oss-sonatype  下载Nexus Repository Manager OSS软件包 ...

  3. JAVA课堂-动手动脑1

    一.Enum:一般用来表示一组相同类型的常量.对这些属性用常量的好处是显而易见的,不仅可以保证单例,且比较时候可以用”==”来替换equals,枚举对象里面的值都必须是唯一的. 代码: public  ...

  4. 使用RedisMQ 做一次分布式改造

    引言 熟悉TPL Dataflow博文的朋友可能记得这是个单体程序,使用TPL Dataflow 处理工作流任务, 在使用Docker部署的过程中, 有一个问题一直无法回避: 在单体程序部署的瞬间会有 ...

  5. MyBatis 核心配置综述之 ResultSetHandler

    目录 ResultSetHandler 简介 ResultSetHandler 创建 ResultSetHandler 处理结果映射 DefaultResultSetHandler 源码解析 我们之前 ...

  6. Struts1.x 跨站脚本(XSS)漏洞的解决

    一. 演示XSS   当访问一个不存在的网址时,例如[url]http://localhost:8080/demo/noAction.do[/url],那么Struts处理后都会跳到提示“Invali ...

  7. 科普向 + 折腾向 ——你了解磁盘、分区、文件系统、GPT、UEFI吗?在笔记本上安装五个系统是怎样的体验?

    [Windows 7 + Windows 8 (PE) + Windows 10 + deepin-Linux + MacOS X] 前言:随着软硬件技术的发展UEFI引导逐渐取代传统BIOS引导,最 ...

  8. 关于JSP页面的静态包含和动态包含

    JSP中有两种包含:静态包含:<%@include file="被包含页面"%> 和 动态包含:<jsp:include page="被包含页面&quo ...

  9. 我的C语言学习1

    学习是快乐的,尤其是从之前看到一个程序的一头雾水到大致懂了是怎么回事,这个过程是兴奋开心的,让我不断的前进,不能自拔,今天就要结束,总结一下. 1.1-第一个C语言 #include<stdio ...

  10. RDIFramework.NET敏捷开发框架通过SignalR技术整合即时通讯(IM)

    1.引言 即时通讯(IM)是RDIFramework.NET敏捷开发框架全新提供的一个基于Web的即时通讯.内部聊天沟通的工具.界面美观大方对于框架内部进行消息的沟通非常方便.基于RDIFramewo ...