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 ...
随机推荐
- Effective C++ 38-42
38.绝不要又一次定义继承而来的缺省參数值. 又一次定义函数缺省參数值意味着又一次定义函数.而非虚函数不能又一次定义,所以将就考虑不能又一次定义虚函数的缺省參数值的原因:虚函数是动态绑定的而缺省參数值 ...
- MySQL中int(5) 中的5代表什么意思?
对于INT型,MySQL支持指定显示宽度例如:int(5):表示如果数值宽度小于5位,则填满宽度,保证总宽度为5位.默认为int(11),配合zerofill可以看到效果. DROP TABLE IF ...
- ActiveMQ基本介绍
1.ActiveMQ服务器工作模型 通过ActiveMQ消息服务交换消息.消息生产者将消息发送至消息服务,消息消费者则从消息服务接收这些消息.这些消息传送操作是使用一组实现 ActiveM ...
- ribbon区域亲和配置一例
只需在springboot的配置文件中添加以下内容即可: eureka.instance.metadata-map.zone=left 该配置是一个eureka客户端的配置,并且该客户端使用了ribb ...
- PHP开发安全问题
1.不相信表单 对于一般的Javascript前台验证,由于无法得知用户的行为,例如关闭了浏览器的javascript引擎,这样通过POST恶意数据到服务器.需要在服务器端进行验证,对每个php脚本验 ...
- MySQL-关于事务的使用
如果你一次执行单条查询语句, 则没有必要启用事务支持, 数据库默认支持SQL执行期间的读一致性, 如果你一次执行多条查询语句, 例如统计查询, 报表查询, 在这种场景下, 多条查询SQL必须保证整体的 ...
- JedisClient(示例)
拷贝 import java.io.IOException; import java.util.HashSet; import java.util.Map; import java.util.Set; ...
- 老毛桃pe装机工具备份系统
电脑故障可以说是难以避免的,误操作或者修改了哪个设置系统就莫名其妙崩溃了.这在日常使用当中并不鲜见,许多用户就会寻求备份系统方法.有没有好的一键备份系统教程可以参考呢?在本篇教程中,就容我跟大家讲讲怎 ...
- 去掉cb中括号的匹配
Settings->Editor->General settings->Indent options->Brace completion``
- 解决修改计算机名后tfs连接不上的错误
1,用vs 自带的工具命令 tf workspaces 查看集合 2,执行命令: >tf workspaces /collection:https://aaaa.visualstudio.com ...