zoukankan      html  css  js  c++  java
  • UVa 10766 Organising the Organisation (生成树计数)

    题意:给定一个公司的人数,然后还有一个boss,然后再给定一些人,他们不能成为直属上下级关系,问你有多少种安排方式(树)。

    析:就是一个生成树计数,由于有些人不能成为上下级关系,也就是说他们之间没有边,没说的就是有边,用Matrix-Tree定理,很容易就能得到答案,注意题目给定的可能有重复的。

    对于基尔霍夫矩阵,就是度数矩阵,减去邻接矩阵,一处理就OK了。

    代码如下:

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include <cstdio>
    #include <string>
    #include <cstdlib>
    #include <cmath>
    #include <iostream>
    #include <cstring>
    #include <set>
    #include <queue>
    #include <algorithm>
    #include <vector>
    #include <map>
    #include <cctype>
    #include <cmath>
    #include <stack>
    #include <sstream>
    #include <bitset>
    #define debug() puts("++++");
    #define gcd(a, b) __gcd(a, b)
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define freopenr freopen("in.txt", "r", stdin)
    #define freopenw freopen("out.txt", "w", stdout)
    using namespace std;
    
    typedef long long LL;
    typedef unsigned long long ULL;
    typedef pair<int, int> P;
    const int INF = 0x3f3f3f3f;
    const LL LNF = 1e16;
    const double inf = 0x3f3f3f3f3f3f;
    const double PI = acos(-1.0);
    const double eps = 1e-8;
    const int maxn = 100 + 50;
    const int mod = 500500;
    const int dr[] = {-1, 0, 1, 0};
    const int dc[] = {0, 1, 0, -1};
    const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
    int n, m;
    const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    inline bool is_in(int r, int c){
      return r > 0 && r <= n && c > 0 && c <= m;
    }
    
    LL a[maxn][maxn];
    int in[maxn];
    
    LL solve(){
      LL ans = 1;
      for(int i = 1; i < n; ++i){
        for(int j = 1+i; j < n; ++j)
          while(a[j][i]){
            LL t = a[i][i] / a[j][i];
            for(int k = i; k < n; ++k)
              a[i][k] -= t * a[j][k];
            for(int k = i; k < n; ++k)
              swap(a[i][k], a[j][k]);
          }
        if(a[i][i] == 0)  return 0;
        ans *= a[i][i];
      }
      return abs(ans);
    }
    
    int main(){
      int k;
      while(scanf("%d %d %d", &n, &m, &k) == 3){
        for(int i = 1; i <= n; ++i){
          for(int j = i+1; j <= n; ++j)
            a[i][j] = a[j][i] = -1;
          in[i] = n - 1;
        }
        for(int i = 0; i < m; ++i){
          int u, v;
          scanf("%d %d", &u, &v);
          if(a[u][v] == -1)  --in[v],  --in[u];
          a[u][v] = a[v][u] = 0;
        }
        for(int i = 1; i <= n; ++i)  a[i][i] = in[i];
        LL ans = solve();
        printf("%lld
    ", ans);
      }
      return 0;
    }
    

      

  • 相关阅读:
    mysql的binlog日志格式
    Git的基本使用
    Tomcat安装部署
    [ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)]
    云盘的创建及使用
    ntp服务器配置
    如何更改mysql的密码策略?
    Centos6 升级glibc-2.17,解决Requires: libc.so.6(GLIBC_2.14)(64bit)错误解决方法
    Git的基本使用
    UES
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/7384338.html
Copyright © 2011-2022 走看看