zoukankan      html  css  js  c++  java
  • POJ 3050 Hopscotch

    暴力DFS

    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<vector>
    #include<algorithm>
    using namespace std;
    
    int a[10][10];
    bool flag[2000000];
    int ans;
    int dir[4][2]={
        {1,0},
        {-1,0},
        {0,1},
        {0,-1}
    };
    
    
    void dfs(int x,int y,int num,int deep)
    {
        if(deep==5)
        {
            if(flag[num]==0)
            {
                flag[num]=1;
               // printf("%d
    ",num);
                ans++;
            }
            return;
        }
    
        for(int i=0;i<4;i++)
        {
            int newx=x+dir[i][0];
            int newy=y+dir[i][1];
    
            if(newx>=1&&newx<=5)
                if(newy>=1&&newy<=5)
                    dfs(newx,newy,num*10+a[newx][newy],deep+1);
        }
    }
    
    int main()
    {
        for(int i=1;i<=5;i++)
            for(int j=1;j<=5;j++)
                scanf("%d",&a[i][j]);
        ans=0; memset(flag,0,sizeof flag);
        for(int i=1;i<=5;i++)
            for(int j=1;j<=5;j++)
                dfs(i,j,a[i][j],0);
        printf("%d
    ",ans);
    
        return 0;
    }
  • 相关阅读:
    内置函数二
    通信的几个程序
    TCP协议和UDP协议
    异常处理
    logging模块
    网络编程一些概念
    hashlib
    序列化模块
    time,sys,os模块
    random模块
  • 原文地址:https://www.cnblogs.com/zufezzt/p/5328116.html
Copyright © 2011-2022 走看看