zoukankan      html  css  js  c++  java
  • P2196 挖地雷

    ---------------------------

    我跟你们说,这就是道假的黄题,普及难度还差不多,太水了

    ---------------------------

    提议没啥好说的,搜索就是了

    ---------------------------

    题目链接:Miku

    --------------------------

     1 /*
     2 这是道假的黄题 
     3 
     4 */
     5 
     6 
     7 
     8 
     9 #include<iostream>
    10 #include<algorithm>
    11 #include<cstring> 
    12 #include<queue>
    13 #include<cstdio>
    14 
    15 using namespace std;
    16 int now[21];//当前顺序 
    17 int ans[21];//答案顺序 
    18 int cnt;//答案 
    19 int vis[21];//回溯记录 
    20 int tu[21][21];//联通 
    21 int v[21];//价值 
    22 int n;
    23 int x;
    24 void dfs(int p,int k,int cntt){
    25     if(vis[p])
    26     return ;
    27     vis[p]=1;
    28     now[k]=p;
    29     for(int i=1;i<=n;++i)
    30     {
    31         if(i!=p&&tu[p][i]&&!vis[i])//不会重复挖=联通+挖没挖过 
    32         {
    33             dfs(i,k+1,cntt+v[i]);//递归 
    34             vis[i]=0;
    35         }
    36     }
    37     if(cntt>cnt)
    38     {
    39         cnt=cntt;//记录 
    40         for(int i=1;i<=n;++i)
    41         {
    42             ans[i]=now[i];//更新路径 
    43         }
    44     }
    45     now[k]=0;//这个也要额外处理 
    46 }
    47 
    48 int main(){
    49     cin>>n;
    50     for(int i=1;i<=n;++i)
    51         {
    52             cin>>v[i];
    53         }
    54     for(int i=1;i<=n;++i)
    55     {
    56         for(int j=i+1;j<=n;++j){
    57         cin>>x;
    58         if(x)
    59         tu[i][j]=1;
    60         }
    61     }
    62     for(int i=1;i<=n;++i)
    63     {
    64         dfs(i,1,v[i]);
    65         vis[i]=0;
    66     }
    67     for(int i=1;i<=n;++i)
    68     {
    69         if(!ans[i])
    70         break;
    71         else
    72         cout<<ans[i]<<" ";
    73     }
    74     cout<<endl<<cnt;
    75     return 0;
    76 }
    AC

    ----------------------------

    Have a good day.

  • 相关阅读:
    牢骚与javascript中的this
    Vim 命令整理
    跟我一起写 Makefile
    Scikit-Learn模块学习笔记——数据预处理模块preprocessing
    Scikit-Learn模块学习笔记——数据集模块datasets
    Markdown 完全指南
    Shell命令行操作
    init_ir_技术实现篇
    ch2 创建和销毁对象
    ch6 影响 MySQLServer 性能的相关因素
  • 原文地址:https://www.cnblogs.com/For-Miku/p/11025111.html
Copyright © 2011-2022 走看看