题意:给一个2*n的矩形块,求把它分成k个连通块的方法数。(有公共边即视为联通)

思路:由于宽度只有2,于是很容易设计状态使问题满足阶段性以及无后效性。具体来说,令dp[i][j][0]和dp[i][j][1]表示把前i行分成j个连通块最后两个格子分别属于和不属于同一个连通块的方法数,于是有下面的状态转移方程:

dp[i][j][0]=dp[i-1][j-1][0..1]+dp[i-1][j][0]+dp[i-1][j][1]*2

dp[i][j][1]=dp[i-1][j-2][0..1]+dp[i-1][j][1]+dp[i-1][j-1][0..1]*2

 #pragma comment(linker, "/STACK:10240000,10240000")

 #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <map>
#include <queue>
#include <deque>
#include <cmath>
#include <vector>
#include <ctime>
#include <cctype>
#include <set>
#include <bitset>
#include <functional>
#include <numeric>
#include <stdexcept>
#include <utility> using namespace std; #define mem0(a) memset(a, 0, sizeof(a))
#define mem_1(a) memset(a, -1, sizeof(a))
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define rep_up0(a, b) for (int a = 0; a < (b); a++)
#define rep_up1(a, b) for (int a = 1; a <= (b); a++)
#define rep_down0(a, b) for (int a = b - 1; a >= 0; a--)
#define rep_down1(a, b) for (int a = b; a > 0; a--)
#define all(a) (a).begin(), (a).end()
#define lowbit(x) ((x) & (-(x)))
#define constructInt4(name, a, b, c, d) name(int a = 0, int b = 0, int c = 0, int d = 0): a(a), b(b), c(c), d(d) {}
#define constructInt3(name, a, b, c) name(int a = 0, int b = 0, int c = 0): a(a), b(b), c(c) {}
#define constructInt2(name, a, b) name(int a = 0, int b = 0): a(a), b(b) {}
#define pchr(a) putchar(a)
#define pstr(a) printf("%s", a)
#define sstr(a) scanf("%s", a)
#define sint(a) scanf("%d", &a)
#define sint2(a, b) scanf("%d%d", &a, &b)
#define sint3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define pint(a) printf("%d\n", a)
#define test_print1(a) cout << "var1 = " << a << endl
#define test_print2(a, b) cout << "var1 = " << a << ", var2 = " << b << endl
#define test_print3(a, b, c) cout << "var1 = " << a << ", var2 = " << b << ", var3 = " << c << endl
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a) typedef unsigned int uint;
typedef long long LL;
typedef pair<int, int> pii;
typedef vector<int> vi; const int dx[] = {, , -, , , , -, -};
const int dy[] = {-, , , , , -, , - };
const int maxn = 1e3 + ;
const int md = ;
const int inf = 1e9 + ;
const LL inf_L = 1e18 + ;
const double pi = acos(-1.0);
const double eps = 1e-; template<class T>T gcd(T a, T b){return b==?a:gcd(b,a%b);}
template<class T>bool max_update(T &a,const T &b){if(b>a){a = b; return true;}return false;}
template<class T>bool min_update(T &a,const T &b){if(b<a){a = b; return true;}return false;}
template<class T>T condition(bool f, T a, T b){return f?a:b;}
template<class T>void copy_arr(T a[], T b[], int n){rep_up0(i,n)a[i]=b[i];}
int make_id(int x, int y, int n) { return x * n + y; } int dp[][][]; void init() {
dp[][][] = ;
dp[][][] = ;
for (int i = ; i <= ; i ++) {
rep_up1(j, * i) {
dp[i][j][] = dp[i - ][j][] + dp[i - ][j][] * + dp[i - ][j - ][] + dp[i - ][j - ][];
dp[i][j][] = dp[i - ][j][] + dp[i - ][j - ][] * + dp[i - ][j - ][] * ;
if (j > ) dp[i][j][] += dp[i - ][j - ][] + dp[i - ][j - ][];
dp[i][j][] %= md;
dp[i][j][] %= md;
}
}
} int main() {
//freopen("in.txt", "r", stdin);
init();
int T;
cin >> T;
rep_up0(cas, T) {
int n, k;
cin >> n >> k;
cout << (dp[n][k][] + dp[n][k][]) % md << endl;
}
return ;
}

[hdu4301]DP的更多相关文章

  1. BZOJ 1911: [Apio2010]特别行动队 [斜率优化DP]

    1911: [Apio2010]特别行动队 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 4142  Solved: 1964[Submit][Statu ...

  2. 2013 Asia Changsha Regional Contest---Josephina and RPG(DP)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4800 Problem Description A role-playing game (RPG and ...

  3. AEAI DP V3.7.0 发布,开源综合应用开发平台

    1  升级说明 AEAI DP 3.7版本是AEAI DP一个里程碑版本,基于JDK1.7开发,在本版本中新增支持Rest服务开发机制(默认支持WebService服务开发机制),且支持WS服务.RS ...

  4. AEAI DP V3.6.0 升级说明,开源综合应用开发平台

    AEAI DP综合应用开发平台是一款扩展开发工具,专门用于开发MIS类的Java Web应用,本次发版的AEAI DP_v3.6.0版本为AEAI DP _v3.5.0版本的升级版本,该产品现已开源并 ...

  5. BZOJ 1597: [Usaco2008 Mar]土地购买 [斜率优化DP]

    1597: [Usaco2008 Mar]土地购买 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 4026  Solved: 1473[Submit] ...

  6. [斜率优化DP]【学习笔记】【更新中】

    参考资料: 1.元旦集训的课件已经很好了 http://files.cnblogs.com/files/candy99/dp.pdf 2.http://www.cnblogs.com/MashiroS ...

  7. BZOJ 1010: [HNOI2008]玩具装箱toy [DP 斜率优化]

    1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 9812  Solved: 3978[Submit][St ...

  8. px、dp和sp,这些单位有什么区别?

    DP 这个是最常用但也最难理解的尺寸单位.它与“像素密度”密切相关,所以 首先我们解释一下什么是像素密度.假设有一部手机,屏幕的物理尺寸为1.5英寸x2英寸,屏幕分辨率为240x320,则我们可以计算 ...

  9. android px转换为dip/dp

    /** * 根据手机的分辨率从 dp 的单位 转成为 px(像素) */ public int dipTopx(Context context, float dpValue) { final floa ...

随机推荐

  1. vs 类型定义及语句,随机数

    1  类型定义: 1)小数: 类型         变量名           赋值 decimal       d   :              d=1.2m float             ...

  2. 详解 Arrays类

    请关注本人博文--<详解 普通数组 -- Arrays类 与 浅克隆> Arrays类: 概述: 针对数组进行操作的工具类.它提供了对于数组的值的排序.查找等功能. 现在,本人来展示一下A ...

  3. 2020i春秋新春战疫

    简单的招聘系统 登陆这里就可以注入 查询这里也可以注入 从登陆这里注入把 爆破数据库名 爆破表名 列名 flag 就很奇怪跑出来的东西 重开容器跑一遍列,估计是flaaag.后面可能是发生了502 再 ...

  4. testNG 下载安装

    testNG的安装方法: 一.在线安装 打开eclipse 选择-->help-->Install New Software选项 ,弹出下面的弹框,Work with框输入 http:// ...

  5. XSS语义分析的阶段性总结(一)

    本文作者:Kale 前言 由于X3Scan的研发已经有些进展了,所以对这一阶段的工作做一下总结!对于X3Scan的定位,我更加倾向于主动+被动的结合.主动的方面主要体现在可以主动抓取页面链接并发起请求 ...

  6. 44道JavaScript送命题

    很久以前看过一个老外写的帖子,JavaScript Puzzlers!,直译就是JavaScript难题,里面列举了100道JavaScript选择题,大部分都是让人摸不着头脑的题目,需要仔细琢磨一番 ...

  7. python爬虫面试题集锦及答案

    1.爬取数据后使用哪个数据库存储数据的,为什么? - 2.你用过的爬虫框架或者模块有哪些?优缺点? - 3.写爬虫是用多进程好?还是多线程好? - 4.常见的反爬虫和应对方法? - 5.需要登录的网页 ...

  8. 一个令人兴奋的ES6星特性-结构赋值

    学完了前4节,今天我给大家带来的是一个令人兴奋的特性:解构赋值.这个章节代码片段有点偏多,不过可以放心,一点都不烧脑,还是老样子:简单易懂. 什么是解构赋值 按照一贯的套路,接下来的内容是解释:什么是 ...

  9. 前端JS—显示赋值(一)

    一:js代码必须位于<script>js代码</script> 把js代码放到<body>元素的地步,可以改善显示速度 二:js显示数据 使用 window.ale ...

  10. 2019-2020-1 20199325《Linux内核原理与分析》第二周作业

    冯诺依曼计算机硬件框图: 下面是一个简单的程序example.c. intadd_a_and_b(int a,int b){returna+b;}intmain(){returnadd_a_and_b ...