Number of Amidakuji

思路:dp

dp[i][j]表示经过(i, j) 这个点的方案数

然后一层一层地转移, 对于某一层, 用二进制枚举这一层的连接情况,

判断连接是否符合题意, 然后再进行转移

代码:

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head const int N = , M = ;
const int MOD = 1e9 + ;
int dp[N][M];
int main() {
int h, w, k;
scanf("%d %d %d", &h, &w, &k);
if(w == ) return *puts("");
dp[][] = ;
for (int i = ; i <= h; i++) {
for (int k = ; k < <<(w-); k++) {
bool f = true;
for (int j = ; j < (w-); j++) {
if((k&(<<j)) && (k&(<<j+))) {
f = false;
break;
}
}
if(f) {
for (int j = ; j < w; j++) {
if(j >= && (k&(<<j-))) {
dp[i][j] = (dp[i][j] + dp[i-][j-]) % MOD;
}
else if(j < w- && (k&(<<j))) {
dp[i][j] = (dp[i][j] + dp[i-][j+]) % MOD;
}
else {
dp[i][j] = (dp[i][j] + dp[i-][j]) % MOD;
}
}
}
}
}
printf("%d\n", dp[h][k-]);
return ;
}

AtCoder Beginner Contest 113 D Number of Amidakuji的更多相关文章

  1. AtCoder Beginner Contest 113 C

    C - ID Time limit : 2sec / Memory limit : 1024MB Score: 300 points Problem Statement In Republic of ...

  2. AtCoder Beginner Contest 113 A

    A - Discount Fare Time limit : 2sec / Memory limit : 1024MB Score: 100 points Problem Statement Ther ...

  3. AtCoder Beginner Contest 113 B

    B - Palace Time limit : 2sec / Memory limit : 1024MB Score: 200 points Problem Statement A country d ...

  4. AtCoder Beginner Contest 100 2018/06/16

    A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...

  5. AtCoder Beginner Contest 053 ABCD题

    A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...

  6. AtCoder Beginner Contest 064 D - Insertion

    AtCoder Beginner Contest 064 D - Insertion Problem Statement You are given a string S of length N co ...

  7. AtCoder Beginner Contest 068 ABCD题

    A - ABCxxx Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement This contes ...

  8. AtCoder Beginner Contest 154 题解

    人生第一场 AtCoder,纪念一下 话说年后的 AtCoder 比赛怎么这么少啊(大雾 AtCoder Beginner Contest 154 题解 A - Remaining Balls We ...

  9. AtCoder Beginner Contest 161

    比赛链接:https://atcoder.jp/contests/abc161/tasks AtCoder Beginner Contest 161 第一次打AtCoder的比赛,因为是日本的网站终于 ...

随机推荐

  1. ql常见面试题 受用了

    //转至:http://www.cnblogs.com/GT_Andy/archive/2009/12/25/1921911.html 1. 用一条SQL 语句 查询出每门课都大于80 分的学生姓名 ...

  2. NOIP 2016 蚯蚓 (luogu 2827 & uoj 264) - 鬼畜的优化

    题目描述 本题中,我们将用符号\lfloor c \rfloor⌊c⌋表示对c向下取整,例如:\lfloor 3.0 \rfloor= \lfloor 3.1 \rfloor=\lfloor 3.9 ...

  3. B/S交互过程及tomcat体系结构

    浏览器与服务器交互过程: 1.浏览器根据主机名,如www.baidu.com,去操作系统的hosts文件中查找主机名对应的ip地址. 2.如果查找不到,则会去互联网上的dns服务器上查找主机名对应的i ...

  4. Restful framework【第二篇】APIView

    安装djangorestframework 方式一:pip3 install djangorestframework 方式二:pycharm图形化界面安装 方式三:pycharm命令行下安装(装在当前 ...

  5. POJ 3264 Balanced Lineup (线段树查找最大最小值)

    http://poj.org/problem?id=3264 题意:给你一个长度为n的序列a[N] (1 ≤ N ≤ 50000),询问Q(1 ≤ Q ≤ 200000) 次,每次输出[L, R]区间 ...

  6. 如何在gvim中安装autoproto自动显示函数原型

    cankao: http://www.vim.org/scripts/script.php?script_id=1553 注意, 在gvim中执行的命令, :foo和:!foo 的区别, 跟vim一样 ...

  7. yum仓库中源的配置与使用

    yum 主要功能是更方便的添加/删除/更新RPM 包,自动解决包的倚赖性问题,便于管理大量系统的更新问题. yum 可以同时配置多个资源库(Repository),简洁的配置文件(/etc/yum.c ...

  8. SpringBoot Mybatis 分页插件PageHelper

    添加maven配置: <!-- 分布插件 --> <dependency> <groupId>com.github.pagehelper</groupId&g ...

  9. 【做题】spoj4060 A game with probability——dp

    赛前做题时忽然发现自己概率博弈类dp很弱,心好慌.(获胜概率或最优解期望) 于是就做了这道题,续了特别久. 一开始列dp式子的时候就花了很长时间,首先搞错了两次,然后忘记了根据上一轮dp值直接确定选什 ...

  10. Jenkins-job迁移

    摘自:http://www.cnblogs.com/topplay/p/3899330.html Jenkins迁移job 说明:从一个Jenkins服务器A将现有job迁移到另外一个Jenkins服 ...