zoukankan      html  css  js  c++  java
  • POJ 3050 Hopscotch(dfs,stl)

    用stack保存数字,set判重。dfs一遍就好。(或者编码成int,快排+unique

    #include<cstdio>
    #include<iostream>
    #include<string>
    #include<cstring>
    #include<queue>
    #include<vector>
    #include<stack>
    #include<vector>
    #include<map>
    #include<set>
    #include<algorithm>
    using namespace std;
    
    const int maxn = 5;
    int g[maxn][maxn];
    
    bool inside(int x,int y)
    {
        return x>=0&&x<maxn&&y>=0&&y<maxn;
    }
    
    set<stack<int> > S;
    stack<int> stk;
    const int dx[] = {0,0,-1,1}, dy[] = {1,-1,0,0};
    void dfs(int x,int y)
    {
        if(!inside(x,y)) return;
        if(stk.size() == 6){
            S.insert(stk);
            return ;
        }
        for(int i = 0; i < 4; i++){
            int nx = x+dx[i], ny = y+dy[i];
            if(inside(nx,ny)){
                stk.push(g[nx][ny]);
                dfs(nx,ny);
                stk.pop();
            }
        }
    }
    
    //#define LOCAL
    int main()
    {
    #ifdef LOCAL
        freopen("in.txt","r",stdin);
    #endif
        for(int i = 0; i < maxn; i++){
            for(int j = 0; j < maxn; j++){
                scanf("%d",g[i]+j);
            }
        }
       for(int i = 0; i < maxn; i++)
            for(int j = 0; j < maxn; j++)
                dfs(i,j);
        printf("%d
    ",S.size());
        return 0;
    }
  • 相关阅读:
    wepy框架构建小程序(1)
    百度地图2
    百度地图1
    VS Code 用户自定义代码片段(React)
    JS MarcoTasks MicroTasks
    JS位运算和遍历
    VueX源码分析(5)
    VueX源码分析(4)
    tensorflow 自带的实现函数翻转的函数
    namedtuple
  • 原文地址:https://www.cnblogs.com/jerryRey/p/4889654.html
Copyright © 2011-2022 走看看