USACO 5.4 Betsy's Tour(暴力)
水过,水过,这个程序跑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(暴力)的更多相关文章
- 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) ...
- 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 ...
- Codeforces Round #349 (Div. 1) B. World Tour 暴力最短路
B. World Tour 题目连接: http://www.codeforces.com/contest/666/problem/B Description A famous sculptor Ci ...
- 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.(因为无法到达此状态 ...
- Codeforces 490F. Treeland Tour 暴力+LIS
枚举根+dfs 它可以活 , 我不知道有什么解决的办法是积极的 ...... F. Treeland Tour time limit per test 5 seconds memory limit p ...
- 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 ...
- 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 ...
- Betsy's Tour 漫游小镇(dfs)
Description 一个正方形的镇区分为 N2 个小方块(1 <= N <= 7).农场位于方格的左上角,集市位于左下角.贝茜穿过小镇,从左上角走到左下角,刚好经过每个方格一次.当 N ...
- USACO 完结的一些感想
其实日期没有那么近啦……只是我偶尔还点进去造成的,导致我没有每一章刷完的纪念日了 但是全刷完是今天啦 讲真,题很锻炼思维能力,USACO保持着一贯猎奇的题目描述,以及尽量不用高级算法就完成的题解……例 ...
随机推荐
- 试试markdown
看看有没有wrapper... list first list second list third list fourth list in list 1 list list list > < ...
- Swap Two Nodes in Linked List
Given a linked list and two values v1 and v2. Swap the two nodes in the linked list with values v1 a ...
- 部署Office Web Apps Server并配置其与SharePoint 2013的集成
部署Office Web Apps Server并配置其与SharePoint 2013的集成 Office Web Apps Server 是新的 Office 服务器产品,它提供 Word.P ...
- iOS 利用constraint实现2个控件上下的空白是相等的
说的有点乱,先看个图把 其实这个constrant的目的就是控制两个方形的控件上方和下方的空白大小. 对于每一个方块来说,他们上方和下方的空白是相同的.这种“居中”的设计到处可见.一个控件想实现这种居 ...
- web iphone css 兼容性
解决IPHONE网页兼容(部分字号变大): body{-webkit-text-size-adjust:none;}
- FZU 2148 moon game (计算几何判断凸包)
Moon Game Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit St ...
- Buy Tickets(poj 2828)
题意:排队买票,但是 中途 出现插队情况,比如 0 123,代表值为123的人 插入到 0 的位置,如果后面 出现 0 456,那么新的 0的位置就是 456,123就变成是 1的位置了 分析:这道题 ...
- 一、HTML和CSS基础--HTML+CSS基础课程--第6部分
第十一章 CSS代码缩写,占用更少的带宽 盒模型代码简写 :还记得在讲盒模型时外边距(margin).内边距(padding)和边框(border)设置上下左右四个方向的边距是按照顺时针方向设置的:上 ...
- Android源码编译
参考百度文章: http://jingyan.baidu.com/article/a501d80ce61ad0ec630f5e0b.html
- https_request
<?php $access_token = ); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); } curl_se ...