hdu4090 GemAnd Prince
来源:互联网 发布:vb中trim是什么意思 编辑:程序博客网 时间:2024/05/02 03:44
按规则DFS,细节比较多
BFS会超内存 传送门
//#pragma warning (disable: 4786)//#pragma comment (linker, "/STACK:16777216")//HEAD#include <cstdio>#include <ctime>#include <cstdlib>#include <cstring>#include <queue>#include <string>#include <set>#include <stack>#include <map>#include <cmath>#include <vector>#include <iostream>#include <algorithm>using namespace std;//LOOP#define FF(i, a, b) for(int i = (a); i < (b); ++i)#define FE(i, a, b) for(int i = (a); i <= (b); ++i)#define FED(i, b, a) for(int i = (b); i>= (a); --i)#define REP(i, N) for(int i = 0; i < (N); ++i)#define CLR(A,value) memset(A,value,sizeof(A))//STL#define SZ(V) (int)V.size()#define PB push_back//INPUT#define RI(n) scanf("%d", &n)#define RII(n, m) scanf("%d%d", &n, &m)#define RIII(n, m, k) scanf("%d%d%d", &n, &m, &k)#define RIV(n, m, k, p) scanf("%d%d%d%d", &n, &m, &k, &p)//OUTPUT#define WI(n) printf("%d\n", n)typedef long long LL;typedef unsigned long long ULL;typedef vector <int> VI;const int INF = 100000000;const double eps = 1e-10;const int maxn = 10;const LL MOD = 1e9 + 7;int n, m, k, tot, ans;int mat[maxn][maxn];int dir[][2] = {{-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1}};void change(){ int low = n; FE(j, 1, m) { low = n; FED(i, n, 1) if (mat[i][j]) mat[low--][j] = mat[i][j]; while (low >= 1) mat[low--][j] = 0; } low = 1; FE(j, 1, m) if (mat[n][j]) { if (j != low) { FE(i, 1, n) mat[i][low] = mat[i][j], mat[i][j] = 0; } low++; }}void dfs(int x, int y, int k, bool vis[][maxn]){ mat[x][y] = 0; tot++; vis[x][y] = 1; REP(i, 8) { int xx = x + dir[i][0], yy = y + dir[i][1]; if (mat[xx][yy] == k && !vis[xx][yy]) dfs(xx, yy, k, vis); }}int get(){ int sum[maxn] = {0}, s = 0; FE(i, 1, n) FE(j, 1, m) sum[mat[i][j]]++; FE(i, 1, k) if (sum[i] >= 3) s += sum[i] * sum[i]; return s;}void work(int p){ ans = max(ans, p); if (p + get() <= ans) return; bool vis[maxn][maxn] = {0}; int tmp[maxn][maxn]; FE(i, 1, n) { FE(j, 1, m) if (!vis[i][j] && mat[i][j]) { tot = 0; memcpy(tmp, mat, sizeof (mat)); dfs(i, j, mat[i][j], vis); if (tot >= 3) { change(); work(p + tot * tot); } memcpy(mat, tmp, sizeof(tmp)); } }}int main(){ while (~RIII(n, m, k)) { CLR(mat, 0); FE(i, 1, n) FE(j, 1, m) RI(mat[i][j]); ans = 0; work(0); WI(ans); } return 0;}
- hdu4090 GemAnd Prince
- hdu4090 GemAnd Prince (搜索+剪枝)
- hdu 4090 GemAnd Prince
- hdu 4090 GemAnd Prince
- HDU 4090 GemAnd Prince
- csdn 4090 GemAnd Prince
- hdu 4090 GemAnd Prince
- hdu 4090 GemAnd Prince (dfs)
- hdu 4090 GemAnd Prince(dfs)
- 【HDU4090】Gem and Prince-DFS+可行性剪枝
- HDU 4090 GemAnd Prince 暴搜+剪枝
- hdu 4090 GemAnd Prince DFS+启发剪枝
- 解题报告:HDU 4090 GemAnd Prince 搜索
- 2011 ACM/ICPC 北京赛区现场赛解题:GemAnd Prince
- hdu 4090 GemAnd Prince dfs+bfs+最优性剪枝
- HDU 4090 GemAnd Prince (DFS+BFS)/(DFS+DFS)
- hdu 4090 GemAnd Prince (bfs+dfs+模拟)
- 2011 北京 hdu 4090--GemAnd Prince(搜索)
- Python与C之间的相互调用(Python C API及Python ctypes库)
- gh列表交叉原理
- C++函数形参可以new吗?
- Ural 1220. Stacks
- Beyond Bags of Features Spatial Pyramid Matching for Recognizing Natural Scene Categorie
- hdu4090 GemAnd Prince
- Linux必学的60个命令
- 关于volatile和(*(unsigned long *)&jiffies)++
- c++学习笔记
- Linux,win双系统, 开机引导设置
- 所见即所得:8款实用HTML5开发框架
- Bumblebee2 双目测量基本原理
- 流程图符号及流程图的例子
- hdu4085 Peach Blossom Spring