描述

For a string of n bits x1, x2, x3, …, xn,  the adjacent bit count of the string  is given by     fun(x) = x1*x2 + x2*x3 + x3*x 4 + … + xn-1*x n
which counts the number of times a 1 bit is adjacent to another 1 bit. For
example:

Fun(011101101) = 3

Fun(111101101) = 4

Fun (010101010) = 0

Write a program which takes as
input integers n and p and returns the number of bit strings
x of n bits (out of 2ⁿ) that satisfy  Fun(x)
= p.

For
example, for 5 bit strings, there are 6 ways of getting fun(x) = 2:

11100,
01110, 00111, 10111, 11101, 11011

输入
On the first line of the input is a single positive integer k, telling the number of test cases to follow. 1 ≤ k ≤ 10 Each case is a single line that contains a decimal integer giving the number (n) of bits in the bit strings, followed by a single space, followed by a decimal integer (p) giving the desired adjacent bit count. 1 ≤ n , p ≤ 100
输出
For each test case, output a line with the number of n-bit strings with adjacent bit count equal to p.
样例输入
2
5 2
20 8
样例输出
6
63426
讲解:看了半天没有看出来,其实就是一个dp问题;看下代码:
 #include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
long long dp[][][];
void fun()
{ int i,j;
memset(dp,,sizeof(dp));
dp[][][]=;dp[][][]=;
for(i=;i<=;i++)
{
dp[i][][]=dp[i-][][]+dp[i-][][];
dp[i][][]=dp[i-][][];
dp[i][i-][]=;
}
for(j=;j<=;j++)
for(i=j+;i<=;i++)
{
dp[i][j][]=dp[i-][j][]+dp[i-][j][];
dp[i][j][]=dp[i-][j][]+dp[i-][j-][];
}
}
int main()
{
fun();
int t,m,n;
cin>>t;
while(t--)
{
cin>>m>>n;
cout<<dp[m][n][]+dp[m][n][]<<endl;
}
return ;
}

nyoj 715 Adjacent Bit Counts的更多相关文章

  1. Adjacent Bit Counts(01组合数)

    Adjacent Bit Counts 4557 Adjacent Bit CountsFor a string of n bits x 1 , x 2 , x 3 ,..., x n , the a ...

  2. BNU4286——Adjacent Bit Counts——————【dp】

    Adjacent Bit Counts Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: %lld      Jav ...

  3. POJ 3786 dp-递推 Adjacent Bit Counts *

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

  4. Adjacent Bit Counts(uvalive)

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

  5. POJ 3786 Adjacent Bit Counts (DP)

    点我看题目 题意 :给你一串由1和0组成的长度为n的数串a1,a2,a3,a4.....an,定义一个操作为AdjBC(a) = a1*a2+a2*a3+a3*a4+....+an-1*an.输入两个 ...

  6. Adjacent Bit Counts(动态规划 三维的)

    /** 题意: 给出一个01串 按照题目要求可以求出Fun(X)的值 比如: 111 Fun(111)的值是2: 输入: t (t组测试数据) n k (有n位01串 Fun()的值为K) 输出:有多 ...

  7. 河南省第六届ACM程序设计大赛

    C:  最舒适的路线 (并查集) #include<cstdio> #include<cstring> #include<iostream> #include< ...

  8. Week__8

    Monday_ 今晚补了扔鸡蛋问题的动态规划问题,补了这道题,感觉视野又开阔了些. 写了一道思维题cf 1066A 数字逻辑后半节听得打脑壳,现在很晚了,明天再看叭. Tuesday_ 今晚补了 ad ...

  9. poj 1804 (nyoj 117)Brainman : 归并排序求逆序数

    点击打开链接 Brainman Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 7810   Accepted: 4261 D ...

随机推荐

  1. UVa 10642 - Can You Solve It?

    题目:二维平面上的整数点.用路径链接起来(0,0)->(1.0)->(0.1)->(2,0)->.. 给你两点坐标.求两点间步长(在路径上的距离). 分析:简单题. 我们发现点 ...

  2. JavaScript 纯粹对象

    JavaScript 纯粹对象 1.定义: 通过 "{}" 或者 "new Object" 创建的对象,像new Date(),new String()都不是纯 ...

  3. 传统数据库没落,OLTP新型数据库发展火热

    參考资料: (1) <OLTP Through the Looking Glass, and What We Found There> (2) <The End of an Arch ...

  4. 解决 只能通过chrome网上应用商店安装该程序

    第一种方法: 右击 Chrome 桌面快捷方式,选择-”属性”-”快捷方式”,然后在”目标”一栏尾部添加参数 -enable-easy-off-store-extension-install 第二种方 ...

  5. 【Oracle】性能优化

    优化原则 1.在select语句中避免使用* 2.使用Truncate清空表 2.1语法 Truncate [table|cluster] shema.[table_name][cluster_nam ...

  6. Python C/C++ 拓展使用接口库(build-in) ctypes 使用手册

    Python C/C++ 拓展使用接口库(build-in) ctypes 使用手册 ctypes 是一个Python 标准库中的一个库.为了实现调用 DLL,或者共享库等C数据类型而设计.它可以把这 ...

  7. centos7编译python3.6与原有的2.7共存

    在某些场景下我们可能需要python2.7和python3这两个版本进行共存,我在工作中也遇到过这样的问题,所以今天来总结下我的安装过程, 我的是用源码包安装的,安装的是python3.6的版本. 安 ...

  8. oracle10-11数据库下载

    Oracle数据库官方下载,需要注册oracle账号,方可下载! 11G 7个压缩包含义: p102025301120——Linux-x86-64_1of7.zip             datab ...

  9. java多线程(三)之售票案例

    售票案例: 火车站3个窗口售100张票. 1.自定义类SellTicket.java package com.test.com.pers.thread; /** * Created by yadong ...

  10. PAT 1086 Tree Traversals Again

    PAT 1086 Tree Traversals Again 题目: An inorder binary tree traversal can be implemented in a non-recu ...