Permutations CodeForces - 736D (矩阵逆)
生活随笔
收集整理的這篇文章主要介紹了
Permutations CodeForces - 736D (矩阵逆)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
對于刪除每個對(x,y), 可以發現他對答案的貢獻為代數余子式$A_{xy}$
復習了一下線代后發現代數余子式可以通過伴隨矩陣求出, 即$A_{xy}=A^*[y][x]$, 伴隨矩陣$A^*=|A|A^{-1}$可以通過高斯消元$O(\frac{n^3}{\omega})$求出
#include <iostream> #include <algorithm> #include <cstdio> #include <math.h> #include <set> #include <map> #include <queue> #include <string> #include <string.h> #include <bitset> #define REP(i,a,n) for(int i=a;i<=n;++i) #define PER(i,a,n) for(int i=n;i>=a;--i) #define hr putchar(10) #define pb push_back #define lc (o<<1) #define rc (lc|1) #define mid ((l+r)>>1) #define ls lc,l,mid #define rs rc,mid+1,r #define x first #define y second #define io std::ios::sync_with_stdio(false) #define endl '\n' using namespace std; typedef long long ll; typedef pair<int,int> pii; const int P = 1e9+7, INF = 0x3f3f3f3f; ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;} ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;} ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;} //headconst int N = 2010; bitset<2*N> g[N]; int x[N*N], y[N*N], n, m;int main() {scanf("%d%d", &n, &m);REP(i,1,n) g[i][i+n]=1;REP(i,1,m) {scanf("%d%d", x+i, y+i);g[x[i]][y[i]]=1;}REP(i,1,n) {REP(j,i,n) if (g[j][i]) {swap(g[i],g[j]);break;}REP(j,1,n) if (j!=i&&g[j][i]) g[j]^=g[i];}REP(i,1,m) puts(g[y[i]][x[i]+n]?"NO":"YES"); }?
轉載于:https://www.cnblogs.com/uid001/p/10619399.html
總結
以上是生活随笔為你收集整理的Permutations CodeForces - 736D (矩阵逆)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java lock可重入_Java源码解
- 下一篇: 归并排序(转)