[USACO 6.4.3]Wisconsin Squares
Posted albertxwz
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[USACO 6.4.3]Wisconsin Squares相关的知识,希望对你有一定的参考价值。
题解
暴搜即可.
代码
/* TASK:wissqu LANG:C++ */ #include <cstdio> #include <cstring> using namespace std; char matrix[8][8], path[16][10]; bool v[4][4], flag; int ans, num[5] = {3, 3, 3, 4, 3}; bool judge(int x0, int y0, int x1, int y1, int k) { for (int i = x0; i <= x1; ++i) for (int j = y0; j <= y1; ++j) if (i >= 0 && i < 4 && j >= 0 && j < 4 && matrix[i][j] == k + ‘A‘) return false; return true; } void dfs(int dep) { if (dep == 16) { if (flag) { for (int i = 0; i < 16; ++i) printf("%s\n", path[i]); flag = false; } ans++; return; } for (int u = 0; u < 5; ++u) if (num[u]) { num[u]--; for (int i = 0; i < 4; ++i) for (int j = 0; j < 4; ++j) if (v[i][j] && judge(i-1, j-1, i+1, j+1, u)) { v[i][j] = false; if (flag) { path[dep][0] = u + ‘A‘; path[dep][1] = ‘ ‘; path[dep][2] = i + ‘0‘ + 1; path[dep][3] = ‘ ‘; path[dep][4] = j + ‘0‘ + 1; } char tmp = matrix[i][j]; matrix[i][j] = u + ‘A‘; dfs(dep + 1); matrix[i][j] = tmp; v[i][j] = true; } num[u]++; } } int main() { freopen("wissqu.in", "r", stdin); freopen("wissqu.out", "w", stdout); for (int i = 0; i < 4; ++i) scanf("%s", matrix[i]); memset(v, true, sizeof(v)); memset(path, 0, sizeof(path)); flag = true; dfs(0); printf("%d\n", ans); return 0; }
以上是关于[USACO 6.4.3]Wisconsin Squares的主要内容,如果未能解决你的问题,请参考以下文章
PingCAP 与 Wisconsin-Madison 大学建立科研合作,探索 Key-Value 存储系统的智能管理与自动调整
使用 scikit learn 在 Python 中导入数据集以解决机器学习问题数据集 Wisconsin Breast Cancer