水过,水过,这个程序跑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. poj3295

    Tautology Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10453   Accepted: 3967 Descri ...

  2. Java--时间处理

    package javatest; import java.text.SimpleDateFormat; import java.util.Date; class timeTest{ public s ...

  3. MySQL Profiling 的使用

    MySQL Profiling 的使用 在本章第一节中我们还提到过通过 Query Profiler 来定位一条 Query 的性能瓶颈,这里我们再详细介绍一下 Profiling 的用途及使用方法. ...

  4. WCDMA是什么意思?CDMA是什么意思?GSM是什么意思

    有些朋友在购买3G智能手机的时候会遇到这样的困惑,为什么相同的手机会有不同手机网络制式之分呢?有的支持WCDMA/GSM,有的支持CDMA/GSM,到底自己应该选购哪一种手机好呢?WCDMA是什么意思 ...

  5. 如何下载google play免费应用的apk文件

    到这里: http://apps.evozi.com/apk-downloader/ 一看便知.

  6. 【Python】Python AES 对称加密示例

    代码: import sys from Crypto.Cipher import AES from binascii import b2a_hex, a2b_hex AES_SECRET_KEY = ...

  7. bat批量去除文件首行和合并到文件

    bat批量去除文件首行 set n=1 :starline for %%j in (*.txt) do ( :3 if exist D:\work\test\new_%n%.txt (set /a n ...

  8. iOS 推荐一个下载用的第三方库

    AFNetworking有下载功能,但是下载功能比较基本,要实现复杂下载功能需要自己写一些代码.今天在github上找到了一个下载功能的开源项目,非常不错,链接如下:https://github.co ...

  9. iOS block 声明时和定义时的不同格式

    今天写程序时,在实现一个block时总提示格式错误,对比api的block参数格式,没发现错误.后来查阅了资料,发现这两个格式是不同的! 具体格式见下方 NSString * (^testBlock) ...

  10. 在SQLServer处理中的一些问题及解决方法 NEWSEQUENTIALID()

    一.DBLINK性能问题select * from dbsource.dbname.dbo.table where guid in (select guid from tablechangelog w ...