Metal Steak

Hard to eat

  C++博客 :: 首页 :: 联系 :: 聚合  :: 管理
  0 Posts :: 79 Stories :: 0 Comments :: 0 Trackbacks

公告

aaaaaaaaaaaa

常用链接

留言簿(1)

我参与的团队

搜索

  •  

最新评论

#include <iostream>
using namespace std;

int
map[
1001][1001], n, ans1 = 0, ans2 = 99999, vst[1001][1001];
const int delta[8][2= { { 01 }, { 11 }, { 10 }, { 1-1 }, { 0-1 }, { -1-1 }, { -10 }, { -11 } };

struct
point
{
    
int
    x, y;
    point()
    {
        x 
= y = 0;
    }
};

void
__read__()
{
    cin 
>> n;
    
forint i = 1; i <= n; i++ )
        
forint j = 1; j <= n; j++ )
            cin 
>> map[i][j];
}

void
__dfs__( point p, 
int step )
{
    
if( p.x == n && p.y == 1 )
    {
        ans1
++;
        
if( step < ans2 )
            ans2 
= step;
        
return;
    }
    
forint i = 0; i < 8; i++ )
    {
        point pp 
= p;
        pp.x 
+= delta[i][0];
        pp.y 
+= delta[i][1];
        
if( pp.x > 0 && pp.x <= n
         
&& pp.y > 0 && pp.y <= n )
            
if!map[pp.y][pp.x] && !vst[pp.y][pp.x] )
            {
                vst[pp.y][pp.x] 
= 1;
                __dfs__( pp, step 
+ 1 );
                vst[pp.y][pp.x] 
= 0;
            }
    }
}

void
__outp__()
{
    cout 
<< ans1 << endl << ans2 << endl;
}

int
main()
{
    point source;
    __read__();
    __dfs__( source, 
-1 );
    __outp__();

    
return 0;
}

posted on 2009-09-15 21:21 mad4alcohol 阅读(201) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航:   博客园   博客园最新博文   博问   管理