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 ...
随机推荐
- 网站中超链接方式直接添加QQ好友
使用情景: 在图中点击图片,会弹出添加qq好友的窗口进行好友添加. 链接如下: tencent://AddContact/?fromId=45&fromSubId=1&subcmd=a ...
- 常见的前端UI框架
Bootstrap 首先说 Bootstrap,估计你也猜到会先说或者一定会有这个( 呵呵了 ),这是说明它的强大之处,拥有框架一壁江山的势气.自己刚入道的时候本着代码任何一个字母都得自己敲出来挡我者 ...
- SPOJ 74. Divisor Summation 分解数字的因子
本题有两个难点: 1 大量的数据输入.没处理好就超时 - 这里使用buffer解决 2 因子分解的算法 a)暴力法超时 b)使用sieve(筛子),只是当中的算法逻辑也挺不easy搞对的. 数值N因子 ...
- 关于linux的添加永久静态路由的static-routes方法
一:使用 route 命令添加 使用route 命令添加的路由,机器重启或者网卡重启后路由就失效了,方法: //添加到主机的路由 # route add –host 192.168.1.11 dev ...
- This Handler class should be static or leaks might occur,Handler和Context使用的注意事项!
Android中.在使用到Handler的时候,假设按例如以下代码编写: private Handler handler; @Override public void onCreate(Bundle ...
- 递归和for循环
# -*- coding: utf-8 -*- #python 27 #xiaodeng #http://www.cnblogs.com/BeginMan/p/3223356.html #递归2 '非 ...
- Centos6.5搭建dhcpd服务
dhcpd动态获取ip地址,对于小型局域网很便利的.在不大的网络社会静态ip也是不错的! 环境 centos6.5 10.10.24.1 (dns-server) winxp sp3 (clie ...
- 【mysql】Innodb三大特性之double write
1.doublewrite buffer(mysql官方的介绍) InnoDB uses a novel file flush technique called doublewrite. Before ...
- RabbitMQ消息队列(六):使用主题进行消息分发[转]
在上篇文章RabbitMQ消息队列(五):Routing 消息路由 中,我们实现了一个简单的日志系统.Consumer可以监听不同severity(严重级别)的log.但是,这也是它之所以叫做简单日志 ...
- 使用Wireshark mac下抓取分析iphone数据包 --IOS端
mac系统版本:mac 10.10 Yosemite xcode版本:6.3.1 在追踪bug或者分析借鉴其他公司的app通讯思路时,抓包这件事是非常有必要的.下面说说Wireshark怎么截获iph ...