AtCoder Beginner Contest 113 D 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的更多相关文章
- AtCoder Beginner Contest 113 C
C - ID Time limit : 2sec / Memory limit : 1024MB Score: 300 points Problem Statement In Republic of ...
- AtCoder Beginner Contest 113 A
A - Discount Fare Time limit : 2sec / Memory limit : 1024MB Score: 100 points Problem Statement Ther ...
- AtCoder Beginner Contest 113 B
B - Palace Time limit : 2sec / Memory limit : 1024MB Score: 200 points Problem Statement A country d ...
- AtCoder Beginner Contest 100 2018/06/16
A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...
- AtCoder Beginner Contest 053 ABCD题
A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...
- AtCoder Beginner Contest 064 D - Insertion
AtCoder Beginner Contest 064 D - Insertion Problem Statement You are given a string S of length N co ...
- AtCoder Beginner Contest 068 ABCD题
A - ABCxxx Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement This contes ...
- AtCoder Beginner Contest 154 题解
人生第一场 AtCoder,纪念一下 话说年后的 AtCoder 比赛怎么这么少啊(大雾 AtCoder Beginner Contest 154 题解 A - Remaining Balls We ...
- AtCoder Beginner Contest 161
比赛链接:https://atcoder.jp/contests/abc161/tasks AtCoder Beginner Contest 161 第一次打AtCoder的比赛,因为是日本的网站终于 ...
随机推荐
- linux的/etc/passwd、/etc/shadow、/etc/group和/etc/gshadow—关于用户和组的配置文件
1./etc/passwd 存储用户信息 [root@oldboy ~]# head /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bi ...
- Python爬虫(二)——豆瓣图书决策树构建
前文参考: https://www.cnblogs.com/LexMoon/p/douban1.html Matplotlib绘制决策树代码: # coding=utf-8 import matpl ...
- LINUX学习 - 磁盘分区 + 开机自动挂载 + 性能测试
在看鸟哥linux私房菜,发现不少有趣的东西,真是相见恨晚. 情境:建立一个新的filesystem挂在/srv/myproject目录下,并让其开机自动挂载到目录,该目录给project群组共享,其 ...
- [c/c++] programming之路(6)、ASCII码,数据类型、随机数、字符转换及拼接等
一.变量 #include<stdio.h> #include<stdlib.h> void main0(){ //数据使用必须在范围内,否则产生溢出 unsigned +;/ ...
- 移动端(微信等)使用 vConsole 调试 console
参考链接:https://blog.csdn.net/m0_37036014/article/details/80113635
- AnswerOpenCV一周佳作欣赏(0615-0622)
一.How to make auto-adjustments(brightness and contrast) for image Android Opencv Image Correction i' ...
- 【python54--爬虫2】
1.有道翻译 ''' |-- 代码思路解析: |-- 1.拿到网址首先查看network内Headers的:Request URL:User-Agent:From Data,这几个就是代码所需要的ur ...
- Linux系统PWM驱动【转】
本文转载自:https://blog.csdn.net/BorntoX/article/details/51879786 硬件平台:IMX6 内核版本:kernel3.0.35 在linux内核中有一 ...
- 【Hadoop 分布式部署 一 :分布式部署准备虚拟机 】
一.将IP配置为静态 按照 下面的操作将IP配置为静态IP 这个静态的IP地址 是你自己设置的,只要符合虚拟机的IP段就可以.最后点击 Apply 需要root密码 将网络断开 (在网络图标左键 ...
- jsp的九大内置对象及作用
内置对象名 类型 request HttpServletRequest ...