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 ...
 
随机推荐
- Qt使用一个事件队列对所有发出的事件进行维护(QObject的event()函数相当于dispatch函数),用EventLabel 继承QLabel作为例子(简单明了) good
			
事件(event)是由系统或者 Qt 本身在不同的时刻发出的.当用户按下鼠标.敲下键盘,或者是窗口需要重新绘制的时候,都会发出一个相应的事件.一些事件在对用户操作做出响应时发出,如键盘事件等:另一些事 ...
 - 多选列表Select之双击删除与添加Demo
			
双击任一Select控件,查看效果: srcA srcC srcB targetC targetB targetA 源码: <html> <head> <script ...
 - Java冒泡排序,Java对象冒泡排序
			
今天呆公司特别无聊,百度了一下Java机试题,看到一个冒泡排序. 粘上我全部的代码: 实体类: package accp.com.internet;/** * 人物类 * @author xuxiao ...
 - [LeetCode]题解(python):034-Search for a Range
			
题目来源 https://leetcode.com/problems/search-for-a-range/ Given a sorted array of integers, find the st ...
 - Java学习-017-EXCEL 文件读取实例源代码
			
众所周知,EXCEL 也是软件测试开发过程中,常用的数据文件导入导出时的类型文件之一,此文主要讲述如何通过 EXCEL 文件中 Sheet 的索引(index)或者 Sheet 名称获取文件中对应 S ...
 - .net 4.0 ValidateRequest="false"
			
在安装了Visual Studio 2010 Beta2之后,当页面输入框默认情况下输入"<"或者">"的时候.按照访问策略,这将导致一些安全问题, ...
 - keepalived对nginx高可用演练脚本
			
keepalived对nginx高可用演练脚本 参考文章:http://deidara.blog.51cto.com/400447/302402/ .安装nginx.keepalived.epel-r ...
 - jQuery操作控件
			
在项目中添加前台控件radio,操作两个div的显示和隐藏,其实是一个很简单的问题,但是费了老大劲才完成,也就是jQuery操作控件的一些基础知识.方法有三种,简单介绍: 1.给元素设置style属性 ...
 - JBOSS安全配置
			
1.jmx-console登录的用户名和密码设置 默认情况访问http://localhost:8080/jmx-console就可以浏览jboss的部署管理的一些信息,不需要输入用户名和密码,使用起 ...
 - Android --ListView分页
			
参考博客:Android ListView分页加载(服务端+android端)Demo 监听OnScrollListener事件 class OnListScrollListener implemen ...