POJ 简单搜索
2012-03-21 15:57
218 查看
简单搜索 | 深度优先搜索 | poj2488,poj3083,poj3009,poj1321 |
广度优先搜索 | poj2251,poj1426,poj3126,poj3087.poj3414 poj 1606 | |
简单搜索技巧和剪枝 | poj2531,poj1416,poj2676,poj1129 |
好恶心的题。。。应该用深搜的,我用的bfs,wa掉,改成dfs,还是wa。。。注意向八个方向扩展的顺序,保证输出结果按字典序排列。
int dir[8][2] = {{-2, -1},{-2, 1},{-1, -2},{-1, 2},{1, -2},{1, 2},{2, -1},{2, 1}};
贡献无数wa,T_T
poj 3083
求左优先和右优先的时候用dfs,注意顺序。
int Left[4][2] = {{1, 0}, {0, -1}, {-1, 0}, {0, 1}};
int Right[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
View Code
#include <iostream> #include <cstring> #include <cstdio> #include <cmath> #include <cstdlib> using namespace std; const int N = 50; const int RAND = 100000; bool sub ; int mp ; int n; int solve() { int i, j, t, sum = 0, res = 0; memset(sub, 0, sizeof(sub)); for(i = 0; i < RAND; ++i) { t = rand()%n; sub[t] = !sub[t]; for(j = 0; j < n; ++j) { if(sub[j] == sub[t]) { sum -= mp[j][t]; } else { sum += mp[j][t]; } } res = max(sum, res); } return res; } int main() { //freopen("data.in", "r", stdin); int i, j; while(~scanf("%d", &n)) { for(i = 0; i < n; ++i) { for(j = 0; j < n; ++j) { scanf("%d", &mp[i][j]); } } printf("%d\n", solve()); } return 0; }
POJ 1129
图的着色问题。暴力回溯。详见:http://blog.csdn.net/suwei19870312/article/details/5282932
相关文章推荐
- poj 1166 简单搜索
- [kuangbin带你飞]专题1 简单搜索 B - Dungeon Master POJ - 2251
- 棋盘问题 POJ - 1321 (简单DFS搜索)
- POJ 1321【棋盘问题】 简单搜索
- poj 1166 简单搜索
- POJ 3278 Catch That Cow(kuangbin带你飞 专题一:简单搜索)
- POJ 1033-Defragment 简单搜索
- kuangbin专题一 简单搜索 E,POJ 1426 Find The Multiple
- [kuangbin带你飞]专题一 简单搜索 POJ - 1321
- poj1426 Find The Multiple 简单搜索
- [kuangbin带你飞]专题一 简单搜索C - Catch That Cow(POJ 3278)
- [kuangbin带你飞]专题一 简单搜索 E - Find The Multiple poj 1426
- [kuangbin带你飞]专题1 简单搜索 C - Catch That Cow POJ - 3278
- POJ 1321 棋盘问题---[kuangbin带你飞]专题一 简单搜索
- POJ 3984 迷宫问题(kuangbin带你飞 专题一:简单搜索)
- POJ 3279 Fliptile(kuangbin带你飞 专题一:简单搜索)
- 简单搜索(数独)poj 2676 Sudoku
- POJ 3087 Shuffle'm Up(kuangbin带你飞 专题一:简单搜索)专题一完结
- [kuangbin带你飞]专题一 简单搜索-D - Fliptile POJ - 3279
- POJ 3126-Prime Path 简单搜索 BFS