zoukankan      html  css  js  c++  java
  • DFS HDOJ 2614 Beat

    题目传送门

     1 /*
     2     题意:处理完i问题后去处理j问题,要满足a[i][j] <= a[j][k],问最多能有多少问题可以解决
     3     DFS简单题:以每次处理的问题作为过程(即行数),最多能解决n个问题,相同的问题(行数)不再考虑
     4     详细解释:http://blog.csdn.net/libin56842/article/details/41909429
     5 */
     6 #include <cstdio>
     7 #include <iostream>
     8 #include <cstring>
     9 #include <algorithm>
    10 #include <cmath>
    11 #include <string>
    12 using namespace std;
    13 
    14 const int MAXN = 15 + 10;
    15 const int INF = 0x3f3f3f3f;
    16 int a[MAXN][MAXN];
    17 int used[MAXN];
    18 int n;
    19 int ans;
    20 
    21 void DFS(int s, int cost, int cnt)
    22 {
    23     ans = max (ans, cnt);
    24     if (cnt == n)    return ;
    25     for (int k=1; k<=n; ++k)
    26     {
    27         if (a[s][k] >= cost && !used[k])
    28         {
    29             used[k] = 1;
    30             DFS (k, a[s][k], cnt+1);
    31             used[k] = 0;
    32         }
    33     }
    34 }
    35 
    36 int main(void)        //HDOJ 2614 Beat
    37 {
    38     //freopen ("N.in", "r", stdin);
    39 
    40     while (~scanf ("%d", &n))
    41     {
    42         memset (used, 0, sizeof (used));
    43         for (int i=1; i<=n; ++i)
    44         {
    45             for (int j=1; j<=n; ++j)
    46             {
    47                 scanf ("%d", &a[i][j]);
    48             }
    49         }
    50 
    51         ans = -1;    used[1] = 1;
    52         for (int i=2; i<=n; ++i)
    53         {
    54             used[i] = 1;
    55             DFS (i, a[1][i], 2);
    56             used[i] = 0;
    57         }
    58 
    59         printf ("%d
    ", ans);
    60     }
    61 
    62     return 0;
    63 }
    编译人生,运行世界!
  • 相关阅读:
    Java 异常
    【转】Java 内部类总结
    【转】Java中的static关键字解析
    【转】事务及事务隔离级别
    【转】事务并发的问题
    【转】hibernate对象三种状态
    iOS指南针
    CoreLocation 定位
    swift 2.2 语法 (下)
    swift 2.2 语法 (中)
  • 原文地址:https://www.cnblogs.com/Running-Time/p/4381091.html
Copyright © 2011-2022 走看看