点我看题目

题意 :给你一串由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)的更多相关文章

  1. POJ 3786 dp-递推 Adjacent Bit Counts *

    Adjacent Bit Counts Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 599   Accepted: 502 ...

  2. BNU4286——Adjacent Bit Counts——————【dp】

    Adjacent Bit Counts Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: %lld      Jav ...

  3. 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 ...

  4. 【POJ 3071】 Football(DP)

    [POJ 3071] Football(DP) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4350   Accepted ...

  5. poj 3311(状态压缩DP)

    poj  3311(状态压缩DP) 题意:一个人送披萨从原点出发,每次不超过10个地方,每个地方可以重复走,给出这些地方之间的时间,求送完披萨回到原点的最小时间. 解析:类似TSP问题,但是每个点可以 ...

  6. poj 1185(状态压缩DP)

    poj  1185(状态压缩DP) 题意:在一个N*M的矩阵中,‘H'表示不能放大炮,’P'表示可以放大炮,大炮能攻击到沿横向左右各两格,沿纵向上下各两格,现在要放尽可能多的大炮使得,大炮之间不能相互 ...

  7. poj 3254(状态压缩DP)

    poj  3254(状态压缩DP) 题意:一个矩阵里有很多格子,每个格子有两种状态,可以放牧和不可以放牧,可以放牧用1表示,否则用0表示,在这块牧场放牛,要求两个相邻的方格不能同时放牛,即牛与牛不能相 ...

  8. poj 2324 Anniversary party(树形DP)

    /*poj 2324 Anniversary party(树形DP) ---用dp[i][1]表示以i为根的子树节点i要去的最大欢乐值,用dp[i][0]表示以i为根节点的子树i不去时的最大欢乐值, ...

  9. poj 2486 Apple Tree(树形DP 状态方程有点难想)

    Apple Tree Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9808   Accepted: 3260 Descri ...

随机推荐

  1. Mysql增加主键或者更改表的列为主键的sql语句

                                                                                                        ...

  2. sublime text3 针对于前端开发必备的插件

    1.emmet--前身Zen coding:HTML/CSS代码快速编写神器 2.jQuery Package for sublime Text:如果你离不开jQuery的话,这个必备-- 3.JS ...

  3. 降kipmi0的CPU

    echo 100 >/sys/module/ipmi_si/parameters/kipmid_max_busy_us

  4. Bootstrap学习笔记(二) 表单

    在Bootstrap学习笔记(一) 排版的基础上继续学习Bootstrap的表单,编辑器及head内代码不变. 3-1 基础表单 单中常见的元素主要包括:文本输入框.下拉选择框.单选按钮.复选按钮.文 ...

  5. linux下进入root

    baoyu@ubuntu:~$ sudo password root sudo: password: command not found baoyu@ubuntu:~$ sudo passwd roo ...

  6. STAD Parameters

    STAD related parameters:   1. stat/file  -- define the file name of the actual STAD content – defaul ...

  7. 7.JAVA_SE复习(文件)

    文件和流 1.什么是节点流和处理流 InputStream & OutputStream Reader & Writer 乃节点流, 前面加File之类的名词 的节点流 其余加动词的均 ...

  8. IIS上的错误与解决方案

    1.未在本地计算机上注册“Microsoft.Jet.OLEDB.4.0”提供程序. 解决方案:在IIS上打开该网站应用程序池-->高级设置-->启动32位程序-->选True

  9. .NET Web后台动态加载Css、JS 文件,换肤方案

    后台动态加载文件代码: //假设css文件:TestCss.css #region 动态加载css文件 public void AddCss() { HtmlGenericControl _CssFi ...

  10. 【转】winform与web 按钮button去掉边框

    ref:http://blog.csdn.net/wangzh300/article/details/5264316 WinForm的话 设置Button属性的FlatStyle为Flat,并且设置F ...