• HDU


    HDU - 5852

    就是个裸的LGV定理套一下, 求下行列式的值。

    #pragma GCC optimize(2)
    #pragma GCC optimize(3)
    #pragma GCC optimize(4)
    #include<bits/stdc++.h>
    #define LL long long
    #define LD long double
    #define ull unsigned long long
    #define fi first
    #define se second
    #define mk make_pair
    #define PLL pair<LL, LL>
    #define PLI pair<LL, int>
    #define PII pair<int, int>
    #define SZ(x) ((int)x.size())
    #define ALL(x) (x).begin(), (x).end()
    #define fio ios::sync_with_stdio(false); cin.tie(0);
    
    using namespace std;
    
    const int N = 100 + 7;
    const int inf = 0x3f3f3f3f;
    const LL INF = 0x3f3f3f3f3f3f3f3f;
    const int mod = (int)1e9 + 7;
    const double eps = 1e-8;
    const double PI = acos(-1);
    
    template<class T, class S> inline void add(T &a, S b) {a += b; if(a >= mod) a -= mod;}
    template<class T, class S> inline void sub(T &a, S b) {a -= b; if(a < 0) a += mod;}
    template<class T, class S> inline bool chkmax(T &a, S b) {return a < b ? a = b, true : false;}
    template<class T, class S> inline bool chkmin(T &a, S b) {return a > b ? a = b, true : false;}
    
    //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    
    int n, k;
    int a[N], b[N];
    int mat[N][N];
    
    const int FN = (int)2e5 + 7;
    int F[FN], Finv[FN], inv[FN];
    
    int solve(int a[N][N], int n) {
        int sign = 0;
        int ans = 1;
        for(int i = 0; i < n; i++) {
            for(int j = i + 1; j < n; j++) {
                int x = i, y = j;
                while(a[y][i]) {
                    int t = a[x][i] / a[y][i];
                    for(int k = i; k < n; k++) {
                        a[x][k] = (a[x][k] - 1LL * a[y][k] * t) % mod;
                    }
                    swap(x, y);
                }
                if(x != i) {
                    for(int k = 0; k < n; k++) swap(a[i][k], a[x][k]);
                    sign ^= 1;
                }
            }
            if(a[i][i] == 0) return 0;
            else ans = 1LL * ans * a[i][i] % mod;
    
        }
        if(sign != 0) ans *= -1;
        if(ans < 0)ans += mod;
        return ans;
    }
    
    int calc(int x, int y) {
        if(x < 0 || y < 0) return 0;
        return 1LL * F[x + y] * Finv[x] % mod * Finv[y] % mod;
    }
    
    void prepare() {
        F[0] = Finv[0] = inv[1] = 1;
        for(int i = 2; i < FN; i++) inv[i] = 1LL * (mod - mod / i) * inv[mod % i] % mod;
        for(int i = 1; i < FN; i++) F[i] = 1LL * F[i - 1] * i % mod;
        for(int i = 1; i < FN; i++) Finv[i] = 1LL * Finv[i - 1] * inv[i] % mod;
    }
    
    int main() {
        prepare();
        int T; scanf("%d", &T);
        while(T--) {
            scanf("%d%d", &n, &k);
            for(int i = 0; i < k; i++) {
                scanf("%d", &a[i]);
            }
            for(int i = 0; i < k; i++) {
                scanf("%d", &b[i]);
            }
            if(n == 1) {
                puts("1");
                continue;
            }
            for(int i = 0; i < k; i++) {
                for(int j = 0; j < k; j++) {
                    mat[i][j] = calc(n - 1, b[j] - a[i]);
                }
            }
            printf("%d
    ", solve(mat, k));
        }
        return 0;
    }
    
    /*
    */
  • 相关阅读:
    杭电OJ 输入输出练习汇总
    七月读书笔记
    情报分析报告阅读笔记
    情报研究与分析入门阅读笔记
    旁观者攻击
    域前置技术相关学习
    CC攻击和C2的区别
    DNS投毒学习分析总结
    数字证书2.0版本学习总结
    《在树洞里》-感悟
  • 原文地址:https://www.cnblogs.com/CJLHY/p/11409553.html
Copyright © 2020-2023  润新知