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 ...
随机推荐
- 解决 maven 项目启动 提示 class not find
第一种方法: 项目 --> .classpath <classpathentry exported="true" kind="con" path=& ...
- 在Ubuntu Server是配置iptables防火墙
iptables 是一个安装在Ubuntu Server上的默认防火墙.在正常的ubuntu安装过程中,iptables是被安装上了的,但是它默认允许所有的流量(不管防火墙是否是无效的) 关于ipta ...
- EXCEPTION-El表达式
CreateTime-- Author:Marydon 声明:异常类文章主要是记录了我遇到的异常信息及解决方案,解决方案大部分都是百度解决的,(这里只是针对我遇到的做个汇总),特此声明! stud ...
- 成为JavaGC专家(3)—如何监控Java垃圾回收机制(转载)
原文:http://www.importnew.com/3146.html 为什么需要优化GC 或者说的更确切一些,对于基于Java的服务,是否有必要优化GC?应该说,对于所有的基于Java的服务,并 ...
- Jquery.getJSON的缓存问题的处理方法
$.getJSON()存在缓存问题,如果其调用的url之前曾经调用过的话,回调函数就会直接在缓存里取得想要得值,而不是进入到后台 在项目中遇到一个问题,在火狐下,$.getJSON();请求数据一 ...
- CentOS 6.4 配置DNS
vi /etc/resolv.conf 写入以下内容并保存: nameserver x.x.x.x 重启服务以生效: service network restart
- flume的memeryChannel中transactionCapacity和sink的batchsize需要注意事项
一. fluem中出现,transactionCapacity查询一下,得出一下这些: 最近在做flume的实时日志收集,用flume默认的配置后,发现不是完全实时的,于是看了一下,原来是memery ...
- HTTP1.1协议请求方面参数
请求信息 GET / HTTP/1.1 ->请求行 Accept: */* Accept-Languag ...
- oracle客户端服务端字符集-解决乱码
查询server段字符集 select userenv('language') from dual 查询client段字符集 select * from v$nls_parameters NLS_LA ...
- HDUOJ-----3591The trouble of Xiaoqian
The trouble of Xiaoqian Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...