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。输入两个数m和k,要求输出满足长度为m的数串进行上述操作能够得到的结果为k的个数。
思路 : 典型DP,列出状态转移方程就行了。dp[i][j][0]代表长度前 i 的数串和为 j 并且当前位置为0.
dp[i][j][1]=dp[i-1][j][0]+dp[i-1][j-1][1];
dp[i][j][0]=dp[i-1][j][1]+dp[i-1][j][0];
#include <iostream>
#include <stdio.h>
#include <string.h> using namespace std; int dp[][][]; void chart()
{
dp[][][]=dp[][][]=;
for(int i = ; i <= ; i++)
{
dp[i][][] = dp[i-][][]+dp[i-][][];
dp[i][][] = dp[i-][][];
}
for(int j = ; j < ; j++)
for(int i = ; i <= ; i++)
{
dp[i][j][]=dp[i-][j][]+dp[i-][j-][];
dp[i][j][]=dp[i-][j][]+dp[i-][j][];
}
}
int main()
{
int n, cas, m, k;
chart() ;
scanf("%d", &n);
while (n--)
{
scanf("%d %d %d", &cas, &m, &k);
printf("%d %d\n",cas, dp[m][k][]+dp[m][k][]);
}
return ;
}
还有一位大神用二维写的,这里
POJ 3786 Adjacent Bit Counts (DP)的更多相关文章
- POJ 3786 dp-递推 Adjacent Bit Counts *
Adjacent Bit Counts Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 599 Accepted: 502 ...
- BNU4286——Adjacent Bit Counts——————【dp】
Adjacent Bit Counts Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: %lld Jav ...
- 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 ...
- 【POJ 3071】 Football(DP)
[POJ 3071] Football(DP) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4350 Accepted ...
- poj 3311(状态压缩DP)
poj 3311(状态压缩DP) 题意:一个人送披萨从原点出发,每次不超过10个地方,每个地方可以重复走,给出这些地方之间的时间,求送完披萨回到原点的最小时间. 解析:类似TSP问题,但是每个点可以 ...
- poj 1185(状态压缩DP)
poj 1185(状态压缩DP) 题意:在一个N*M的矩阵中,‘H'表示不能放大炮,’P'表示可以放大炮,大炮能攻击到沿横向左右各两格,沿纵向上下各两格,现在要放尽可能多的大炮使得,大炮之间不能相互 ...
- poj 3254(状态压缩DP)
poj 3254(状态压缩DP) 题意:一个矩阵里有很多格子,每个格子有两种状态,可以放牧和不可以放牧,可以放牧用1表示,否则用0表示,在这块牧场放牛,要求两个相邻的方格不能同时放牛,即牛与牛不能相 ...
- poj 2324 Anniversary party(树形DP)
/*poj 2324 Anniversary party(树形DP) ---用dp[i][1]表示以i为根的子树节点i要去的最大欢乐值,用dp[i][0]表示以i为根节点的子树i不去时的最大欢乐值, ...
- poj 2486 Apple Tree(树形DP 状态方程有点难想)
Apple Tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9808 Accepted: 3260 Descri ...
随机推荐
- 第五十三篇、OC利用AFN上传视频到服务器
整体思路已经清楚,拿到视频资源,先转为mp4,写进沙盒,然后上传,上传成功后删除沙盒中的文件. 本地拍摄的视频,上传到服务器: //视频转换为MP4 //转码操作... _hud.mode = MBP ...
- 第三十三篇、富文本 NSMutableAttributedString
// 设置颜色等 NSMutableDictionary *arrDic = [NSMutableDictionary dictionary]; arrDic[NSForegroundColorAtt ...
- 学习之spring属性文件注入
package com.my.proper; import org.springframework.beans.factory.annotation.Value; import org.springf ...
- OC2_ARC MRC混合编程
// // main.m // OC2_ARC MRC混合编程 // // Created by zhangxueming on 15/6/19. // Copyright (c) 2015年 zha ...
- Apache使用mysql认证用户
使用MySQL进行认证 第1步:下载MySQL认证模块,并更名为mod_auth_mysql.so文件,并保存在apache的modules目录下 第2步:apache要加载此功能模块 LoadMod ...
- ClassLoader源码
最近找工作,面试网易和微策略,都问到了ClassLoader这个东西,看来应该是比较重要的,所以在这总结一下,嗯,类源码有点长,慢慢看吧. 翻译一下,不当之处欢迎指正. /** * A class l ...
- 值初始化-new
程序如下#include<iostream>using namespace std; int main(){ int *a=new int(1); int *b ...
- Poj 1328 / OpenJudge 1328 Radar Installation
1.Link: http://poj.org/problem?id=1328 http://bailian.openjudge.cn/practice/1328/ 2.Content: Radar I ...
- DataGridView显示时间格式
默认显示时间不显示秒yyyy-MM-dd HH:mm dataGridView.Columns["日期时间字段"].DefaultCellStyle.Format = " ...
- 【转】winform与web 按钮button去掉边框
ref:http://blog.csdn.net/wangzh300/article/details/5264316 WinForm的话 设置Button属性的FlatStyle为Flat,并且设置F ...