题目链接:uva 211 - The Domino Effect
题目大意:给出一些7*8的矩阵,每两个相邻的数字可以表示一个骨牌,问说骨牌有多少种摆法。
解题思路:总共有28块骨牌,dfs枚举每一个位置,考虑当前位置和下面右边组成的骨牌。
#include <stdio.h>
#include <string.h>
const int R = 7;
const int C = 8;
const int N = 30;
const int d[2][2] = {{0, 1}, {1, 0}};
int ans, t[R][C], g[R][C], vis[R][C], rec[N];
bool init() {
ans = 0;
memset(rec, 0, sizeof(rec));
memset(vis, 0, sizeof(vis));
for (int i = 0; i < R; i++)
for (int j = 0; j < C; j++) if (scanf("%d", &g[i][j]) != 1) return false;
return true;
}
void setInit() {
int c = 1;
for (int i = 0; i < R; i++)
for (int j = i; j < R; j++)
t[i][j] = t[j][i] = c++;
}
void put() {
for (int i = 0; i < R; i++) {
for (int j = 0; j < C; j++) printf("%4d", vis[i][j]);
printf("\n");
}
printf("\n");
}
void dfs(int x, int y, int c) {
if (c == 28) {
ans++; put();
return;
}
if (y == C) {
x++; y = 0;
}
if (vis[x][y]) dfs(x, y + 1, c);
else {
for (int i = 0; i < 2; i++) {
int p = x + d[i][0], q = y + d[i][1];
if (p >= R || q >= C || vis[p][q]) continue;
int k = t[g[x][y]][g[p][q]];
if (rec[k]) continue;
vis[x][y] = vis[p][q] = k; rec[k] = 1;
dfs(x, y + 1, c + 1);
vis[x][y] = vis[p][q] = 0; rec[k] = 0;
}
}
}
int main() {
setInit();
int cas = 0;
while (init()) {
if (cas) printf("\n\n\n");
printf("Layout #%d:\n\n", ++cas);
for (int i = 0; i < R; i++) {
for (int j = 0; j < C; j++)
printf("%4d", g[i][j]);
printf("\n");
}
printf("\nMaps resulting from layout #%d are:\n\n", cas);
dfs(0, 0, 0);
printf("There are %d solution(s) for layout #%d.\n", ans, cas);
}
return 0;
}
分享到:
相关推荐
dominoLotusNotes教程软件免费下载web开发---domino8.5安装.pdf
Lotus Domino BS开发--Lotus Domino Designer环境介绍
Lotus Domino BS开发--Lotus Domino平台的概念介绍
IBM AS400资料(7)------配置Domino V65 for iSeries.zip
Dmino集群技术-LOTUS Domino开发平台必备Dmino集群技术-LOTUS Domino开发平台必备
Crosstalk-aware Domino Logic Synthesis
资源名称:Domino原创经典系列视频(11集)资源目录:【】1-原创Domino系列视频:安装和配置第一台domino服务器【】2-原创Domino系列视频:附加服务器注册和配置【】4-原创Domino系列视频:Dominowebaccess配置【】5...
IBM-Domino资料,IBM-Domino培训,IBM-Domino调优,IBM-Domino故障诊断
基于Domino的工作流引擎,李彦澎,夏阳,本文在详细分析工作流模型的基础上,提出了基于Domino的企业级工作流引擎。并简要描述了这种工作流引擎的实现。企业内部的大部分应
domino gates are always ready for evaluation by the time critical inputs arrive and do not precharge until the next gate consumes the result. This paper describes a systematic framework, called skew-...
通过EddieExport软件将domino邮件数据库转换为outlook使用的pst文件。注意本软件其运行环境安装了outlook、notes应用软件,才能完成数据转换。 软件版本:EddieExport4_1_16 个人测试可以完成nsf邮件数据转换为pst...
lotus domino附件开发--ls获取domino安装路径
Domino Verse 10 - 2018 简化版--Domino 服务器 10最新介绍
对domino系统进行兼容重写.
优化 Lotus Domino 服务器性能-domino群集
Domino pieces and game state is working OK, but there are more than a few things missing. First, it's not very pretty. It's in OpenGL, although the perspective is fixed and not very appealing. I ...
Lotus-Domino-web开发培训课件
domino--------------------
COMBEST-DOMINO8.5.1高端服务综合配置