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 n ) 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
题解:求一个长度为p,构造一个价值为n的字符串的方法数;

首先如果我们要构造一个价值为7的字符串,若分为两部分的话,我们有1+6,2+5,3+4等3种方案,对于1+6,我们又可以分为一个子问题,将6分为两部分,以此类推;

这样就满足一个最优子结构;这样我们把原问题可以分为若干子问题,我们用的dp[i][j]表示长度为i-1,价值为j的字符串的方法数,由于最后一位0与1两种情况,我们可以定义3维数组;

dp[i][j][0]=dp[i-1][j][0]+dp[i-1][j][1];

dp[i][j][1]=dp[i-1][j][0]+dp[i-1][j-1][1];

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
typedef long long ll;
const int MAXN=1e3+;
int m,n;
int dp[MAXN][MAXN][];
using namespace std;
int main()
{
cin>>m;
int p,k,u;
while(m--)
{
cin>>p>>k>>u;
memset(dp,,sizeof(dp));
dp[][][]=;
dp[][][]=;
for(int i=;i<=k;i++)
{
for(int j=;j<=u;j++)
{
for(int t=;t<;t++)
{
if(t==)
{
dp[i][j][t]=dp[i-][j][]+dp[i-][j][];
}
else
{
dp[i][j][t]=dp[i-][j][]+dp[i-][j-][];
}
}
}
}
cout<<p<<" "<<dp[k][u][]+dp[k][u][]<<endl;
}
}

][0]+dp[i-1][j-1][1];

Adjacent Bit Counts(uvalive)的更多相关文章

  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. nyoj 715 Adjacent Bit Counts

    描述 For a string of n bits x1, x2, x3, …, xn,  the adjacent bit count of the string  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. UVALive 4868 Palindrometer 暴力

    F - Palindrometer Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit ...

随机推荐

  1. 初次使用git遇到的问题总结

    第一次使用git时,遇到好多问题,但也都是小问题,下边我把这些问题总结一下. 问题一: 创建远程仓库的时候,如果你勾选了Initialize this repository with a README ...

  2. 报错 Inferred type 'S' for type parameter 'S' is not within its bound; 解决办法

    出现情况: Inferred type 'S' for type parameter 'S' is not within its bound; should extends xxxxxx 出现这种问题 ...

  3. 如何在 .NET 库的代码中判断当前程序运行在 Debug 下还是 Release 下

    我们经常会使用条件编译符 #if DEBUG 在 Debug 下执行某些特殊代码.但是一旦我们把代码打包成 dll,然后发布给其他小伙伴使用的时候,这样的判断就失效了,因为发布的库是 Release ...

  4. 用idea将javaweb项目部署到tomcat

    之前在网上找的一些web项目都是用eclipse开发的,想把这些项目导入到idea中,然后部署到tomcat中,在网上找了很多教程,很多都不靠谱,发现网上很多配置都是多余的,其实很多只需要按idea默 ...

  5. docker windows 2016 安装测试

    1. 安装方式      powershell Install-Module-NameDockerMsftProvider-RepositoryPSGallery-Force Install-Pack ...

  6. c#代码加密

    源代码保护:怎样利用MaxtoCode加密dotNet源代码 http://www.webkaka.com/blog/archives/MaxtoCode-encrypt-dotnet-program ...

  7. Oracle 之 Cloning $oracle_home (克隆安装oracle软件)

    用途:Cloning an Oracle Home , 可以免去多台机器重复安装oracle软件 1.停止相关进程[root@node1 bin]# ./crsctl stop cluster -al ...

  8. centos6.6升级安装MySQL5.5(2015/3/4)

    使用系统CentOS 6.6本来已经系统自带安装了mysql 5.1,但是奈何5.1不支持utf8mb4字符集(详见:http://blog.csdn.net/shootyou/article/det ...

  9. bzoj1426(洛谷4550)收集邮票

    题目:https://www.luogu.org/problemnew/show/P4550 全靠看TJ.怎么办?可是感觉好难呀. 首先设出 f[i] 为“买了 i 种,还要买到n种的期望次数”,s[ ...

  10. Error unmarshalling file:/opt/test/jboss/server/defalt/conf/bootstrap.xml

    启动命令:#/usr/local/jboss/bin/run.sh -b 0.0.0.0 -c defalt 启动的defalt写错了,应该写default.