HDU 4064 Carcassonne(插头DP)(The 36th ACM/ICPC Asia Regional Fuzhou Site —— Online Contest)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4064
Square tiles are printed by city segments,road segments and field segments.
The rule of the game is to put the tiles alternately. Two tiles share one edge should exactly connect to each other, that is, city segments should be linked to city segments, road to road, and field to field.
To simplify the problem, we only consider putting tiles:
Given n*m tiles. You can rotate each tile, but not flip top to bottom, and not change their order.
How many ways could you rotate them to make them follow the rules mentioned above?
Each case starts with two number N,M(0<N,M<=12)
Then N*M lines follow,each line contains M four-character clockwise.
'C' indicate City.
'R' indicate Road.
'F' indicate Field.
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL; const int MAXN = ;
const int SIZE = ;
const int MOD = 1e9 + ; struct Hashmap {
int head[SIZE], ecnt;
int to[SIZE], next[SIZE], val[SIZE];
int stk[SIZE], top; Hashmap() {
memset(head, -, sizeof(head));
} void clear() {
while(top) head[stk[--top]] = -;
ecnt = ;
//for(int i = 0; i < SIZE; ++i) if(head[i] != -1) cout<<"error"<<endl;
} void insert(int st, int value) {
int h = st % SIZE;
for(int p = head[h]; ~p; p = next[p]) {
if(to[p] == st) {
val[p] += value;
if(val[p] >= MOD) val[p] -= MOD;
return ;
}
}
if(head[h] == -) stk[top++] = h;
to[ecnt] = st; val[ecnt] = value; next[ecnt] = head[h]; head[h] = ecnt++;
}
} hashmap[], *pre, *cur; char s[MAXN][MAXN][];
int w[];
int n, m, T; int getState(int state, int i) {
return (state >> (i << )) & ;
} void setState(int &state, int i, int val) {
i <<= ;
state = (state & ~( << i)) | (val << i);
} int solve() {
pre = &hashmap[], cur = &hashmap[];
cur->clear();
cur->insert(, );
int maxState = ( << ((m + ) << )) - ;
for(int i = ; i < n; ++i) {
for(int p = ; p < cur->ecnt; ++p)
cur->to[p] = (cur->to[p] << ) & maxState;
for(int j = ; j < m; ++j) {
swap(pre, cur);
cur->clear();
for(int p = ; p < pre->ecnt; ++p) {
int st = pre->to[p];
for(int k = ; k < ; ++k) {
if(j != && w[(int)s[i][j][(k + ) & ]] != getState(st, j)) continue;
if(i != && w[(int)s[i][j][(k + ) & ]] != getState(st, j + )) continue;
int new_st = st;
setState(new_st, j, w[(int)s[i][j][k]]);
setState(new_st, j + , w[(int)s[i][j][(k + ) & ]]);
cur->insert(new_st, pre->val[p]);
}
}
}
}
int res = ;
for(int p = ; p < cur->ecnt; ++p) {
res += cur->val[p];
if(res >= MOD) res -= MOD;
}
return res;
} int main() {
w['F'] = ; w['C'] = ; w['R'] = ;
scanf("%d", &T);
for(int t = ; t <= T; ++t) {
scanf("%d%d", &n, &m);
for(int i = ; i < n; ++i)
for(int j = ; j < m; ++j) scanf("%s", s[i][j]);
printf("Case %d: %d\n", t, solve());
}
}
HDU 4064 Carcassonne(插头DP)(The 36th ACM/ICPC Asia Regional Fuzhou Site —— Online Contest)的更多相关文章
- HDU 4069 Squiggly Sudoku(DLX)(The 36th ACM/ICPC Asia Regional Fuzhou Site —— Online Contest)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4069 Problem Description Today we play a squiggly sud ...
- HDU 4063 Aircraft(计算几何)(The 36th ACM/ICPC Asia Regional Fuzhou Site —— Online Contest)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4063 Description You are playing a flying game. In th ...
- HDU 4031 Attack(离线+线段树)(The 36th ACM/ICPC Asia Regional Chengdu Site —— Online Contest)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4031 Problem Description Today is the 10th Annual of ...
- HDU 5875 Function 【倍增】 (2016 ACM/ICPC Asia Regional Dalian Online)
Function Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total ...
- hdu 5878 I Count Two Three (2016 ACM/ICPC Asia Regional Qingdao Online 1001)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5878 题目大意: 给出一个数n ,求一个数X, X>=n. X 满足一个条件 X= 2^a*3^ ...
- HDU 5437 Alisha’s Party (优先队列)——2015 ACM/ICPC Asia Regional Changchun Online
Problem Description Princess Alisha invites her friends to come to her birthday party. Each of her f ...
- 2014 ACM/ICPC Asia Regional Beijing Site
1001 A Curious Matt 1002 Black And White 1003 Collision 1004 Dire Wolf 1005 Everlasting L 1006 Fluor ...
- 2016 ACM/ICPC Asia Regional Shenyang Online 1009/HDU 5900 区间dp
QSC and Master Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- 2016 ACM/ICPC Asia Regional Shenyang Online 1007/HDU 5898 数位dp
odd-even number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
随机推荐
- SQL2008全部数据导出导入两种方法【转】
方法一:生成脚本导出导入sql2008全部数据 第一步,右键要导出的数据库,任务--生成脚本 第二步,在设置脚本编写选项处,点击--高级(A),选择要编写脚本的数据的类型为:架构和数据 如果找 ...
- 在 mac os 上搭建 git server
前言:之前学习了如何使用 git 后,一直想搭建一个本机搭建一个 git server 的,一开始不知道走了弯路用了 gitosis,折腾了我好几天都没配置好.昨晚查资料发现 gitosis 早就过时 ...
- 【C51】单片机芯片之——图解74HC595
第一部部分用于快速查阅使用,详细的使用见文章第二部分 引脚图
- zepto-创建dom
在使用zepto时,为了使得ajax请求回来的数据添加到页面上之后,不至于失去所绑定的事件. 我一般会采用$()创建dom元素节点,然后添加所需要的class和html等等一系列的样式,最基本的是$( ...
- 改变当前shell工作目录
执行脚本时候,只是在当前的shell下开了一个子进程,切换目录的操作只对该进程中相关后续指令有效,但改变不了父进程的目录. 解决方法: 法一: 用 source a.sh就行了. 法二: [fedor ...
- 设计模式:职责链模式(Chain Of Responsibility)
定 义:使多个对象都有机会处理请求,从而避免请求的发送者和接受者之间的耦合关系.将这些对象连成一条链,并沿着这条链传递请求,直到有一个对象处理它为止. 结构图: 处理请求类: //抽象处理类 abs ...
- 20145211 《Java程序设计》第3周学习总结——绝知此事要躬行
教材学习内容总结 4.1何为面向对象 面向对象,面向过程都是一种思想,没有高低之分.面向对象,就像是对冰箱操作,冰箱是一个介质,用法就像是c语言中的结构体,功能定义在对象上.面向对象,角色转变,让我们 ...
- 在magento中如何回复客户的评论
magento — 在magento中如何回复客户的评论 发表于 2012 年 8 月 18 日 agento本身是不带 回复评论的功能的,现成的扩展(无论免费的还是商业的)也没找到,那就自己写一个吧 ...
- sublime text2 操作及插件
sublime text2 1. 文件快速导航: 这是sublime上面很好用的功能之一,ctrl+p可以调出窗口,菜单上的解释是gotoanythings ,确实如其所言,调出窗口后,直接输入关键字 ...
- Java学习-022-Properties 文件数据写入
Properties 配置文件写入主要通过 Properties.setProperty 和 Properties.store 两个方法,此文以一个简单的 properties 文件写入源码做示例. ...