FZU 2107 Hua Rong Dao(暴力回溯)
dfs暴力回溯,这个代码是我修改以后的,里面的go相当简洁,以前的暴力手打太麻烦,我也来点技术含量..
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
#define m 4
int caocao[][] = {,,,,,,,};
int go[][][] = {{{,},{,}},{{,},{,}},{{,}}};
int kind[] = {,,};
int vis[][];
int n,tmp;
void work_caocao(int x,int y)
{
int tmpx,tmpy;
for(int i = ; i < ; i++)
{ tmpx = x + caocao[i][];
tmpy = y + caocao[i][];
vis[tmpx][tmpy] = ;
}
}
bool ok(int x,int y,int k)
{
for(int i = ; i < kind[k]; i++)
{
int tmpx,tmpy;
tmpx = x+go[k][i][],tmpy = y+go[k][i][];
if(vis[tmpx][tmpy]) return false;
if(tmpx > n || tmpy > m) return false;
if(tmpx <= || tmpy <= ) return false;
}
return true;
}
void set_vis(int x,int y,int k,int v)
{
for(int i = ; i < kind[k]; i++)
{
int tmpx,tmpy;
tmpx = x+go[k][i][],tmpy = y+go[k][i][];
vis[tmpx][tmpy] = v;
}
}
void dfs(int x,int y)
{
if(y == m+)
{
x++;
y = ;
}
if(x == n+)
{
tmp++;
return;
}
if(vis[x][y])dfs(x,y+);
for(int i = ; i < ; i++)
{
if(ok(x,y,i))
{
//cout<<x << " "<<y<<endl;
set_vis(x,y,i,);
dfs(x,y+);
set_vis(x,y,i,);
}
}
}
void set_caocao(int x,int y)
{
for(int i = x; i < n; i++)
for(int j = y; j < m; j++)
{
memset(vis,,sizeof(vis));
//cout<<i<<" "<<j<<endl;
work_caocao(i,j);
dfs(,);
}
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int ans[];
ans[] = ,ans[] = ;
for(int i = ;i <= ;i++)
{
n = i;
tmp = ;
set_caocao(,);
ans[i] = tmp;
}
int nn;
scanf("%d",&nn);
printf("%d\n",ans[nn]);
}
}
FZU 2107 Hua Rong Dao(暴力回溯)的更多相关文章
- ACM: FZU 2107 Hua Rong Dao - DFS - 暴力
FZU 2107 Hua Rong Dao Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I6 ...
- FZU 2107 Hua Rong Dao(dfs)
Problem 2107 Hua Rong Dao Accept: 318 Submit: 703 Time Limit: 1000 mSec Memory Limit : 32768 KB Prob ...
- fzu 2107 Hua Rong Dao(状态压缩)
Problem 2107 Hua Rong Dao Accept: 106 Submit: 197 Time Limit: 1000 mSec Memory Limit : 32768 K ...
- foj Problem 2107 Hua Rong Dao
Problem 2107 Hua Rong Dao Accept: 503 Submit: 1054Time Limit: 1000 mSec Memory Limit : 32768 K ...
- FZOJ Problem 2107 Hua Rong Dao
...
- uva 639 Don't Get Rooked 变形N皇后问题 暴力回溯
题目:跟N皇后问题一样,不考虑对角冲突,但考虑墙的存在,只要中间有墙就不会冲突. N皇后一行只能放一个,而这题不行,所以用全图暴力放棋,回溯dfs即可,题目最多就到4*4,范围很小. 刚开始考虑放一个 ...
- Chinese Mahjong UVA - 11210 (暴力+回溯递归)
思路:得到输入得到mj[]的各个牌的数量,还差最后一张牌.直接暴力枚举34张牌就可以了. 当假设得到最后一张牌,则得到了的牌看看是不是可以胡,如果可以胡的话,就假设正确.否者假设下一张牌. 关键还是如 ...
- Magic FZU - 2280 无脑HASH暴力
Kim is a magician, he can use n kinds of magic, number from 1 to n. We use string Si to describe mag ...
- UVaLive 6585 && Gym 100299F Draughts (暴力+回溯)
题意:给定一个 10*10的矩阵,每一个W可以跳过一个B向对角走到#并把B吃掉,并且可以一直跳直到不能动为止,现在是W走的时候,问你最多吃几个B. 析:直接暴力+回溯,深搜就好. 代码如下: #pra ...
随机推荐
- 多个git账户生成多份rsa秘钥实现多个账户同时使用配置
下文分享一个多个git账户生成多份rsa秘钥实现多个账户同时使用配置例子了,这个例子非常的好用对于有多个git的朋友有不小的帮助. 使用过git的童鞋应该对id_rsa秘钥不陌生,总得用github吧 ...
- TD配置安装方式
TD服务器搭建及配置指南 第一:安装前的环境准备 系统需安装IIS作为web服务器(停止IIS的smtp服务). 选择SQL Server2000作为数据库.Win2003需安装SP3. 以管理员登陆 ...
- mysql 表连接
1.子查询是指在另一个查询语句中的SELECT子句. 例句: SELECT * FROM t1 WHERE column1 = (SELECT column1 FROM t2); 其中,SELECT ...
- 修改index.php 清空mylog1.txt
进入编辑php文件vim index.php(无则新建) -->进入命令行模式--输入a(append)-->进入编辑模式-->编辑好-->esc退出编辑模式-->:q! ...
- ASP.NET MVC Controller向View传值的几种方式
上几篇博文提到MVC和WebForm的区别,主要是MVC的Controller和View将传统的WebForm的窗体和后台代码做了解耦,这篇博文简单介绍一下在MVC中Controller向View是如 ...
- LeetCode OJ 82. Remove Duplicates from Sorted List II
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb ...
- HDU1686:Oulipo
Problem Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, w ...
- flash 右键菜单隐藏与修改
来源:http://blog.sina.com.cn/s/blog_7264c84401014fmd.html import flash.ui.ContextMenu;import flash.ui. ...
- swf version 与flash player 对应关系
2013-04-16更新:更新Flash Player 11.7/AIR 3.7正式版. 详细链接FlashPlayer 11.7详情 2013-03-10更新:更新Flash Player 11.6 ...
- Android Studio一直build、一直refreshing、一直buiding gradle project into的终极解决办法
打开我的电脑,打开C:\Users\用户名, 把红圈的文件夹都删了 如果AndroidStudioProjects文件夹里那些project都不重要,也可以跟红圈文件夹删了, 然后再打开android ...