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. java project 项目在 linux 下面部署方法

    1.前提是安装好了响应的开发和部署环境,例如jdk. 2.在Linux下运行可执行Jar包,首先准备jar包,一般的编译工具Eclipse,jbuilder都提供export功能,可以生成jar包. ...

  2. BZOJ3144 Hnoi2013 切糕 【网络流】*

    BZOJ3144 Hnoi2013 切糕 Description Input 第一行是三个正整数P,Q,R,表示切糕的长P. 宽Q.高R.第二行有一个非负整数D,表示光滑性要求.接下来是R个P行Q列的 ...

  3. (2/2) 为了理解 UWP 的启动流程,我从零开始创建了一个 UWP 程序

    每次使用 Visual Studio 的模板创建一个 UWP 程序,我们会在项目中发现大量的项目文件.配置.应用启动流程代码和界面代码.然而这些文件在 UWP 程序中到底是如何工作起来的? 我从零开始 ...

  4. 利用Topshelf把.NET Core Generic Host管理的应用程序部署为Windows服务

    背景 2019第一篇文章. 此文源于前公司在迁移项目到.NET Core的过程中,希望使用Generic Host来管理定时任务程序时,没法部署到Windows服务的问题,而且官方也没给出解决方案,只 ...

  5. MySQL 字段基本操作

    MySQL添加字段的方法并不复杂,下面将为您详细介绍MySQL添加字段和修改字段等操作的实现方法,希望对您学习MySQL添加字段方面会有所帮助. .登录数据库 >mysql -u root -p ...

  6. CH1803 City Game

    题意 这片土地被分成NM个格子,每个格子里写着'R'或者'F',R代表这块土地被赐予了rainbow,F代表这块土地被赐予了freda. 现在freda要在这里卖萌...它要找一块矩形土地,要求这片土 ...

  7. 含锂电池的 PCBA 运输快递时如何包装?

    含锂电池的 PCBA 运输快递时如何包装? PCBA 和电池必须固定. PCBA 和电池必须独立包装. 独立包装的外壳必须为硬包装,防止运输中挤压导致短路. 电池电量在 80% 或以下.

  8. cookie控制登陆时间

    使用cookie实现永久登陆 1,在cookie里面保存账号密码然后和数据库核对(由于我没有使用数据库,就不用了 2,在cookie里面保存时间戳和账号使用加密解密(我也没有使用时间戳 思路,requ ...

  9. SublimeText3搭建go语言开发环境(windows)

    SublimeText3搭建go语言开发环境(windows) 下载并解压:     Sublime Text Build 3021.zip注册:     尽量不要去破解    安装Package C ...

  10. 类的声明与实例化及构造方法析构方法(PHP学习)

    <?php class human{ public static $leg=2; public $name = 'leo'; public $age = '25'; public functio ...