• 师大 11370


    http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11370&courseid=0

    1
    3
    0 -3 1
    3 0 -2
    -1 2 0


    1 3

     反复思考...

     1 #include<iostream>
     2 #include<stdio.h>
     3 #include<cstring>
     4 #include<cstdlib>
     5 #include<queue>
     6 using namespace std;
     7 
     8 int a[21][21],sum[21];
     9 bool hash[(1<<20)+2];
    10 int n;
    11 
    12 void dfs(int k)
    13 {
    14     hash[k]=true;
    15     int i,j;
    16     for(i=0;i<n;i++)
    17     {
    18         if( ((1<<i)&k)>0 && sum[i]>0 && hash[k-(1<<i)]==false)
    19         {
    20             for(j=0;j<n;j++)
    21             {
    22                 if(k&(1<<j))
    23                     sum[j]=sum[j]-a[j][i];
    24             }
    25             dfs((k-(1<<i)));
    26             for(j=0;j<n;j++)
    27             {
    28                 if(k&(1<<j))
    29                     sum[j]=sum[j]+a[j][i];
    30             }
    31         }
    32     }
    33 }
    34 int main()
    35 {
    36     int T,i,j,t;
    37     bool flag;
    38     scanf("%d",&T);
    39     while(T--)
    40     {
    41         scanf("%d",&n);
    42         for(i=0;i<n;i++)
    43         for(j=0;j<n;j++)
    44             scanf("%d",&a[i][j]);
    45         memset(hash,false,sizeof(hash));
    46         for(i=0;i<n;i++)
    47         {
    48             sum[i]=0;
    49             for(j=0;j<n;j++)
    50                 sum[i]=sum[i]+a[i][j];
    51         }
    52         dfs((1<<n)-1);
    53         t=0;flag=false;
    54         for(i=0;i<n;i++)
    55         {
    56             if(hash[1<<i]==true)
    57             {
    58                 if(t==1)printf(" ");
    59                 printf("%d",i+1);
    60                 flag=true;
    61                 t=1;
    62             }
    63         }
    64         if(!flag)printf("0");
    65         printf("
    ");
    66     }
    67     return 0;
    68 }
  • 相关阅读:
    prometheus基础概念
    Prometheus告警处理
    什么是prometheus?
    Prometheus的PromQL
    Prometheus的Exporter详解
    leetcode unique path I&&II
    leetcode Palindrome Partitioning
    leetcode 最大子矩阵(5星推荐)
    leetcode Sum Root to Leaf Numbers 二叉树所有叶节点的路径和
    leetcode Spiral Matrix I
  • 原文地址:https://www.cnblogs.com/tom987690183/p/3649841.html
Copyright © 2020-2023  润新知