设为首页 加入收藏

TOP

利用DFS得出十二张牌的赢法(一)
2013-12-06 09:53:47 来源: 作者: 【 】 浏览:381
Tags:利用 DFS 得出 十二 张牌的

    题意:给出十三章牌,问有几种赢的方法。
    思路:DFS枚举所有的情况,记得剪枝。
    自己想得几组数据。
    7
    1s 1s 2s 2s 3s 3s 4s 4s 5s 5s 6s 6s 7s
    3 1s 4s 7s
    1s 1s 3s 3s 5s 5s 1p 1p 5m 5m 7c 7c 1c
    1 1c
    1s 2s 3s 2c 2c 2c 2p 3p 5m 6m 7m 1p 1p
    2 1p 4p
    1p 1p 2p 3p 4s 5s 6s 7c 7c 3s 3s 2m 2m
    Nooten
    1s 2s 3s 4s 5s 6s 7s 8s 9s 9s 9s 2c 3c
    Nooten
    1s 2s 3s 4s 5s 6s 7s 8s 9s 9s 9s 2c 2c
    4 3s 6s 9s 2c
    1s 9s 1m 9m 1p 9p 1c 2c 3c 4c 5c 6c 7c
    13 1m 9m 1s 9s 1p 9p 1c 2c 3c 4c 5c 6c 7c
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #define LL long long
    #define EPS (1e-8)
    #define Left true
    #define Right false
    using namespace std;
    struct N
    {
    int id,ty;
    }s[15];
    struct E
    {
    int id;
    char ty;
    }st[100000];
    int mark ;
    bool dfs_con;
    bool dfs(int t1,int t2,int eye,int r,int c)
    {
    int i,j;
    if(dfs_con)
    return true;
    for(i = 1;i <= r; ++i)
    {
    for(j = 1;j < (i == r c : 9) ; ++j)
    {
    if(mark[i][j] != 0)
    return false;
    }
    }
    if(eye == 1 && mark[r][c] != 3 && mark[r][c] != 0 && ( (c == 9 && mark[r][c-1] == 0) || (c == 1 && mark[r][c+1] == 0) || (1 < c && c < 9 && mark[r][c+1] == 0 && mark[r][c-1] == 0)))
    {
    return false;
    }
    if(eye == 0 && mark[r][c] == 4 && mark[r][c] == 1 && ( (c == 9 && mark[r][c-1] == 0) || (c == 1 && mark[r][c+1] == 0) || (1 < c && c < 9 && mark[r][c+1] == 0 && mark[r][c-1] == 0)))
    {
    return false;
    }
    if(t1+t2 == 4 && eye)
    {
    dfs_con = true;
    return true;
    }
    for(i = r;i <= 4; ++i)
    {
    for(j = (i == r c : 1) ; j <= 9; ++j)
    {
    if(eye == 0)
    {
    if(mark[i][j] >= 2)
    {
    mark[i][j] -= 2;
    if(dfs(t1,t2,1,i,j) == true)
    return true;
    mark[i][j] += 2;
    }
    }
    if(mark[i][j] >= 3)
    {
    mark[i][j] -= 3;
    if(dfs(t1+1,t2,eye,i,j) == true)
    {
    return true;
    }
    mark[i][j] += 3;
    }
    if(i != 4 && j <= 7 && mark[i][j] >= 1 && mark[i][j+1] >= 1 && mark[i][j+2] >= 1)
    {
    mark[i][j]--;
    mark[i][j+1]--;
    mark[i][j+2]--;
    if(dfs(t1,t2+1,eye,i,j) == true)
    {
    return true;
    }
    mark[i][j]++;
    mark[i][j+1]++;
    mark[i][j+2]++;
    }
    }

   

首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇翻转单词顺序 下一篇怕麻烦的人Gardon 推箱子

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Libevent C++ 高并发 (2025-12-26 00:49:30)
·C++ dll 设计接口时 (2025-12-26 00:49:28)
·透彻理解 C 语言指针 (2025-12-26 00:22:52)
·C语言指针详解 (经典 (2025-12-26 00:22:49)
·C 指针 | 菜鸟教程 (2025-12-26 00:22:46)