水过,水过,这个程序跑7,跑5分钟左右把。。。

 /*
ID: cuizhe
LANG: C++
TASK: betsy
*/
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int p[][],ans,n;
int o[][];
int a[] = {,,,-};
int b[] = {,-,,};
void dfs(int x,int y,int step)
{
int i,j,k;
if(step == n*n)
{
if(x == n&&y == )
{
ans ++;
}
return ;
}
if(p[n][]) return ;
if(p[n-][]&&p[n][])
{
if(x == n-&&y == )
;
else if(x == n&&y == )
;
else
return ;
}
if(n*n - step < o[x][y])
return ;
for(i = ;i < ;i ++)
{
if(x + a[i] >= &&x + a[i] <= n&&y + b[i] >= &&y + b[i] <= n)
{
if(!p[x+a[i]][y+b[i]])
{
p[x+a[i]][y+b[i]] = ;
dfs(x+a[i],y+b[i],step+);
p[x+a[i]][y+b[i]] = ;
}
}
}
return ;
}
int main()
{
int i,j;
freopen("betsy.in","r",stdin);
freopen("betsy.out","w",stdout);
scanf("%d",&n);
if(n == )
{
printf("88418\n");
return ;
}
for(i = ;i <= n;i ++)
{
for(j = ;j <= n;j ++)
{
o[i][j] = n-i + j-;
}
}
p[][] = ;
ans = ;
dfs(,,);
printf("%d\n",ans);
return ;
}

USACO 5.4 Betsy's Tour(暴力)的更多相关文章

  1. USACO 6.5 Betsy's Tour (插头dp)

    Betsy's TourDon Piele A square township has been divided up into N2 square plots (1 <= N <= 7) ...

  2. USACO 1.3 Ski Course Design - 暴力

    Ski Course Design Farmer John has N hills on his farm (1 <= N <= 1,000), each with an integer ...

  3. Codeforces Round #349 (Div. 1) B. World Tour 暴力最短路

    B. World Tour 题目连接: http://www.codeforces.com/contest/666/problem/B Description A famous sculptor Ci ...

  4. USACO Seciton 5.4 Canada Tour(dp)

    因为dp(i,j)=dp(j,i),所以令i>j. dp(i,j)=max(dp(k,j))+1(0<=k<i),若此时dp(i,j)=1则让dp(i,j)=0.(因为无法到达此状态 ...

  5. Codeforces 490F. Treeland Tour 暴力+LIS

    枚举根+dfs 它可以活 , 我不知道有什么解决的办法是积极的 ...... F. Treeland Tour time limit per test 5 seconds memory limit p ...

  6. USACO 3.3 TEXT Eulerian Tour中的Cows on Parade一点理解

    Cows on Parade Farmer John has two types of cows: black Angus and white Jerseys. While marching 19 o ...

  7. Codeforces Round #349 (Div. 2) D. World Tour 暴力最短路

    D. World Tour   A famous sculptor Cicasso goes to a world tour! Well, it is not actually a world-wid ...

  8. Betsy's Tour 漫游小镇(dfs)

    Description 一个正方形的镇区分为 N2 个小方块(1 <= N <= 7).农场位于方格的左上角,集市位于左下角.贝茜穿过小镇,从左上角走到左下角,刚好经过每个方格一次.当 N ...

  9. USACO 完结的一些感想

    其实日期没有那么近啦……只是我偶尔还点进去造成的,导致我没有每一章刷完的纪念日了 但是全刷完是今天啦 讲真,题很锻炼思维能力,USACO保持着一贯猎奇的题目描述,以及尽量不用高级算法就完成的题解……例 ...

随机推荐

  1. 【Hadoop】HIVE 小结概览

    一.HIVE概览小结 二.HIVE安装 Hive只在一个节点上安装即可 .上传tar包 .解压 tar -zxvf hive-.tar.gz -C /cloud/ .配置mysql metastore ...

  2. 47. 数组中出现次数超过一半的数字[Number appears more than half times]

    [题目]:数组中有一个数字出现的次数超过了数组长度的一半,找出这个数字. 例如长度为9的数组{1,2,3,2,2,2,5,4,2}中次数超过了数组长度的一半的数字为2,而长度为8的数组{1,2,3,2 ...

  3. windows下bat批处理实现守护进程

    本文转自网络,由于找不到原作者,因而无法知道出处.如果有幸让原作者看到,请联系我加上.先转载至此. 最近几天加班加疯掉了,天天晚上没法睡.开发部的一个核心程序总是会自己宕机,然后需要手工去起,而这个服 ...

  4. shell脚本去重的几种方法

    测试文件 [root@bogon ~]# cat >test jason jason jason fffffjason 按 Ctr + D保存 1.sort -u [root@bogon ~]# ...

  5. sybaseIQ索引类型和使用注意事项

    1. FP(Fast Projection)此索引为默认的索引形式,在创建表时系统自动设置此索引. 特点:用于SELECT.LIKE '%sys%'.SUM(A+B).JOIN操作等语句. 此类型索引 ...

  6. 101 个 MySQL 的调节和优化的提示(根据实际情况调整,有些已经不适用)

    英文原文:101 Tips to MySQL Tuning and Optimization ( July 12, 2011)翻译:http://www.oschina.net/translate/1 ...

  7. codeforces 483A. Counterexample 解题报告

    题目链接:http://codeforces.com/problemset/problem/483/A 题目意思:给出一个区间 [l, r],要从中找出a, b, c,需要满足 a, b 互质,b, ...

  8. codeforces A. Group of Students 解题报告

    题目链接:http://codeforces.com/problemset/problem/357/A 题目意思:将一堆人分成两组:beginners 和 intermediate coders .每 ...

  9. lucene 搜索引擎使用案例

    1.使用定时框架Quartz.Net创建索引库,引用类库文件有Common.Logging.dll.Lucene.Net.dll,PanGu.dll,PanGu.HighLight.dll,PanGu ...

  10. WPF中的常用类汇总:

    1.FrameworkElement: WPF中大部分的控件都可以转化成FrameworkElement,利用FrameworkElement属性获取相应的值: 2.WPF获取当前工作区域的宽度和高度 ...