zoukankan      html  css  js  c++  java
  • 2019.08.25校内模拟赛Graph


    其实这是道很难的容斥.
    所以我考场上直接考虑了(m=0)的暴力和白给的(m=cfrac{n(n-1)}{2})(10)分.
    白给的那十分是完全图,根据题意就只需要输出(0)就行了.
    而至于(m=0)(40pts),稍加思索就会发现它和错排是双射关系...
    于是,就直接错排就好了.
    但我当时忘了错排公式是什么了...递推式也没想起来...
    于是我就妄想手推容斥形式的错排,但是我死了,没推出来.
    于是我就(10pts)走人了.
    后来在(wqy)的指导下推了出来,长这个亚子:

    [D_n=sum_{i=0}^n {(-1)^i left(egin{array}{c}{n} \ {i}end{array} ight) ( n - i ) ! } ]

    怎么推出来的呢?
    你考虑,强制(i)个点的(p_i=i),那么方案就是(left(egin{array}{c}{n} \ {i}end{array} ight) ( n - i ) !).
    然后我们选出(i)个点就行了,这个东西就这亚子出来辽~~
    (Code:)

    #include <algorithm>
    #include <iostream>
    #include <cstdlib>
    #include <cstring>
    #include <cstdio>
    #include <string>
    #include <vector>
    #include <queue>
    #include <cmath>
    #include <ctime>
    #include <map>
    #include <set>
    #define MEM(x,y) memset ( x , y , sizeof ( x ) )
    #define rep(i,a,b) for (int i = a ; i <= b ; ++ i)
    #define per(i,a,b) for (int i = a ; i >= b ; -- i)
    #define pii pair < int , int >
    #define X first
    #define Y second
    #define rint read<int>
    #define int long long
    #define pb push_back
    
    using std::set ;
    using std::pair ;
    using std::max ;
    using std::min ;
    using std::priority_queue ;
    using std::vector ;
    
    template < class T >
        inline T read () {
            T x = 0 , f = 1 ; char ch = getchar () ;
            while ( ch < '0' || ch > '9' ) {
                if ( ch == '-' ) f = - 1 ;
                ch = getchar () ;
            }
            while ( ch >= '0' && ch <= '9' ) {
                x = ( x << 3 ) + ( x << 1 ) + ( ch - 48 ) ;
                ch = getchar () ;
           }
       return f * x ;
    }
    
    const int mod = 1e9 + 7 ;
    const int N = 2e3 + 100 ;
    
    int n , m , ans ;
    int C[N][N] , g[N] ;
    
    signed main() {
        n = rint () ; m = rint () ; g[0] = 1 ;
        rep ( i , 0 , n ) C[i][0] = 1 ; rep ( i , 1 , n ) g[i] = g[i-1] * i % mod ;
        rep ( i , 1 , n ) rep ( j , 1 , i ) C[i][j] = ( C[i-1][j-1] + C[i-1][j] ) % mod ;
        rep ( i , 0 , n ) ans = ( ans + ( ( i & 1 ) ? - 1 : 1 ) * C[n][i] % mod * g[n-i] % mod ) % mod ;
        printf ("%lld
    " , ans ) ;
        system ("pause") ; return 0 ;
    }
    
    May you return with a young heart after years of fighting.
  • 相关阅读:
    重建二叉树
    数值的整数次方
    二维数组查找
    二进制中1的个数
    LRU算法的精简实现(基于Java)
    华为18.9.5校招笔试题AK
    避免反射和序列化来破坏单例
    Markdown图片存储解决方法-利用阿里云OSS
    基于Java反射的map自动装配JavaBean工具类设计
    多态与类初始化的底层原理
  • 原文地址:https://www.cnblogs.com/Equinox-Flower/p/11408818.html
Copyright © 2011-2022 走看看