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 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的更多相关文章
- 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 ...
- BNU4286——Adjacent Bit Counts——————【dp】
Adjacent Bit Counts Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: %lld Jav ...
- POJ 3786 dp-递推 Adjacent Bit Counts *
Adjacent Bit Counts Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 599 Accepted: 502 ...
- 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 ...
- 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.输入两个 ...
- Adjacent Bit Counts(动态规划 三维的)
/** 题意: 给出一个01串 按照题目要求可以求出Fun(X)的值 比如: 111 Fun(111)的值是2: 输入: t (t组测试数据) n k (有n位01串 Fun()的值为K) 输出:有多 ...
- 河南省第六届ACM程序设计大赛
C: 最舒适的路线 (并查集) #include<cstdio> #include<cstring> #include<iostream> #include< ...
- Week__8
Monday_ 今晚补了扔鸡蛋问题的动态规划问题,补了这道题,感觉视野又开阔了些. 写了一道思维题cf 1066A 数字逻辑后半节听得打脑壳,现在很晚了,明天再看叭. Tuesday_ 今晚补了 ad ...
- poj 1804 (nyoj 117)Brainman : 归并排序求逆序数
点击打开链接 Brainman Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 7810 Accepted: 4261 D ...
随机推荐
- Spring Tool Suite 使用自带maven速度慢---修改settings.xml更新mirror方法
(1)打开sts,windows --> preference,找到maven,并设置如下. (2)修改该文件,如下 <mirror> <id>nexus-aliyun& ...
- git工具 将源码clone到本地指定目录的三种方式
git工具 将源码clone到本地指定目录的三种方式 CreationTime--2018年7月27日15点34分 Author:Marydon 1.情景展示 运行git-bash.exe,输入命 ...
- 修改wamp apache 默认端口
目标:新配置一个虚拟主机,要求端口为8080,但要保证原来的80端口仍可用 1.修改 httpd.conf 开启vhost文件支持 2.httpd-vhosts.conf 中增加,记得把原来的内容全部 ...
- lua入门之二:c/c++ 调用lua及多个函数返回值的获取
当 Lua 调用 C 函数的时候,使用和 C 调用 Lua 同样类型的栈来交互. C 函数从栈中获取她的參数.调用结束后将返回结果放到栈中.为了区分返回结果和栈中的其它的值,每一个 C 函数还会返回结 ...
- Linux下编辑利器vim,vimrc,viminfo的高级用法
1.ci" (由 change operator 和 text-object i" 组成) 这个命令会找到当前光标所在行的下一个 " 括起来的字符串,清除引号裏面的内容, ...
- smokeping with tcpping centos 7 环境
本次环境采用centos7,使用centos6的同学就洗洗睡吧,此外一定要做好时间同步,并且关闭防火墙以及selinux,不然安装可能会失败的哦.时间同步方式如下: yum install ntpda ...
- HDUOJ--------1003 Max Sum
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- java 移位
java中没有2进制的数据类型,对二进制的操作,需要使用三种操作符 << 左移位操作符,算数左移 用来将一个数的二进制位序列左移若干位,高位左移后溢出,舍弃不用,右补0 ...
- input text的所有事件
onBlur 当 text field失去聚焦的时候执行一些代码 onChange 当 text field失去聚焦并且它的值发生变动的时候执行一些代码 onClick 当用户在 text field ...
- Android中如何实现文件下载
最近做一个项目需要从服务器下载图片到本地sdcard,上网查找了一些例子,下面这个比较合适,原文内容如下: 我们在开发中经常需要从服务器下载文件,下载的内容可能有交换的信息,缓存的图片,程 ...