版本比较
勰码金牌学院 S1 课程 16&17. 高斯消元
正文
增加 1 行删除 175 行
306 行未改动全部展开307308309310311312313314315316317318319320321322323324325326327328329330331332311312313314315338316317318319320321322323324348325326327328116 行未改动全部展开445446447448473474475476477478479480481482483484485486487488489490491492449450451452150 行未改动全部展开603604605606651652653654655656657658659660661662663664665666667668669670607608609610228 行未改动全部展开839840841842907908909910911912913914915916917918919920921922923924925926927928843844845846516 行未改动全部展开1363136413651366145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811367136813691370194 行未改动全部展开156515661567156816841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712156915701571157212 行未改动15851586158715881733158915901591159215934 行未改动1598159916001601174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775160216031604160588 行未改动306 行未改动全部展开
时间复杂度 $O(n^3 \log m)$。
```cpp#include<iostream>#include<cstdio>#include<cmath>#define re register#define endl '\n'#define ll long long#define ull unsigned long long#define db double#define fi const int&#define fl const ll&#define ful const ull&#define fc const char&#define fs const string&#define debug() puts("I Love Hina Forever")using namespace std ;namespace IO { template<class T>inline void read(T &x){char c=getchar(),f=false;x=0;while(c<48||c>57) {f|=(c==45),c=getchar();}while(c>=48&&c<=57){x=(x<<3)+(x<<1)+(c^48),c=getchar();}if(f){x=~x+1;}} template<class T,class ...Arg>inline void read(T &x,Arg &...arg){read(x),read(arg...);} template<class T>inline void write(T x){if(x<0){putchar(45),x=~x+1;}if(x>9){write(x/10);}putchar(x%10|48);} template<class T>inline void write(T x,fc c){write(x),putchar(c);}}using namespace IO ;
const int N = 602,MOD = 998244353 ;int n,m,r = 1 ;int p[N] ;bool has_p[N] ;ll a[N][N],ans[N],cnt = 1 ;
inline ll exgcd (ll a,ll b,ll &x,ll &y) { if (!b) { x = 1,y = 0 ; return a ; } re ll g = exgcd(b,a % b,y,x) ; y -= a / b * x ; return g ;}
inline void gauss () { for (re int i = 1 ; i <= n ; ++i) { int mx = r ; for (re int k = r ; k <= n ; ++k) {116 行未改动全部展开
时间复杂度 $O(n^3)$。
```cpp#include<iostream>#include<cstdio>#define re register#define endl '\n'#define ll long long#define ull unsigned long long#define db double#define fi const int&#define fl const ll&#define ful const ull&#define fc const char&#define fs const string&#define debug() puts("I Love Hina Forever")using namespace std ;namespace IO { template<class T>inline void read(T &x){char c=getchar(),f=false;x=0;while(c<48||c>57) {f|=(c==45),c=getchar();}while(c>=48&&c<=57){x=(x<<3)+(x<<1)+(c^48),c=getchar();}if(f){x=~x+1;}} template<class T,class ...Arg>inline void read(T &x,Arg &...arg){read(x),read(arg...);} template<class T>inline void write(T x){if(x<0){putchar(45),x=~x+1;}if(x>9){write(x/10);}putchar(x%10|48);} template<class T>inline void write(T x,fc c){write(x),putchar(c);}}using namespace IO ;const int P = 1e9 + 7,N = 402 ;int n,p[N],r = 1 ;ll a[N][N << 1] ;inline ll qpow (ll a,ll b) {150 行未改动全部展开
代码:
```cpp#include<iostream>#include<cstdio>#define re register#define endl '\n'#define ll long long#define ull unsigned long long#define db double#define fi const int&#define fl const ll&#define ful const ull&#define fc const char&#define fs const string&#define debug() puts("I Love Hina Forever")using namespace std ;namespace IO { template<class T>inline void read(T &x){char c=getchar(),f=false;x=0;while(c<48||c>57) {f|=(c==45),c=getchar();}while(c>=48&&c<=57){x=(x<<3)+(x<<1)+(c^48),c=getchar();}if(f){x=~x+1;}} template<class T,class ...Arg>inline void read(T &x,Arg &...arg){read(x),read(arg...);} template<class T>inline void write(T x){if(x<0){putchar(45),x=~x+1;}if(x>9){write(x/10);}putchar(x%10|48);} template<class T>inline void write(T x,fc c){write(x),putchar(c);}}using namespace IO ;const int N = 602 ;int n,m,r = 1 ;ll a[N][N],ans = 1 ;bool f ;228 行未改动全部展开
求出第 $n$ 行后需要看第 $n$ 行(前面相邻两行会相互制约,但第 $n$ 行没有第 $n+1$ 行进行扭转纠正)最终颜色是否全 $0$,合法就统计 $x_{i,j} = 1$ 的数量。统计最小值。
```cpp#include<iostream>#include<cstdio>#include<bitset>#include<cstring>#define re register#define endl '\n'#define ll long long#define ull unsigned long long#define db double#define fi const int&#define fl const ll&#define ful const ull&#define fc const char&#define fs const string&#define debug() puts("I Love Hina Forever")using namespace std ;namespace IO { template<class T>inline void read(T &x){char c=getchar(),f=false;x=0;while(c<48||c>57) {f|=(c==45),c=getchar();}while(c>=48&&c<=57){x=(x<<3)+(x<<1)+(c^48),c=getchar();}if(f){x=~x+1;}} template<class T,class ...Arg>inline void read(T &x,Arg &...arg){read(x),read(arg...);} template<class T>inline void write(T x){if(x<0){putchar(45),x=~x+1;}if(x>9){write(x/10);}putchar(x%10|48);} template<class T>inline void write(T x,fc c){write(x),putchar(c);}}using namespace IO ;const int N = 18 ;int T,n ;int p[N * N],minn = 1e9 ;bool col[N][N],x[N * N] ;516 行未改动全部展开
也就是说高消的时候去归一某一行,$ans'$ 乘的是某个数而非这个数的**逆元**(当然这是仅当模数是质数时才能用逆元直接算)。
```cpp/*_/ _/ _/_/_/_/_/_/ _/ _/ _/_/_/ _/ _/ _/_/ _/ _/ _/_/ _/ _/ _/ _/ _/ _/ _/_/_/_/_/_/_/ _/ _/ _/ _/ _/ _/_/ _/ _/ _/ _/_/ _/_/_/_/_/_/_/ _/ _/ _/ _/ _/ _/_/ _/ _/_/_/_/_/_/ _/ _/ _/ _/*/#include<iostream>#include<cstdio>#define re register#define endl '\n'#define ll long long#define ull unsigned long long#define db double#define fi const int&#define fl const ll&#define ful const ull&#define fc const char&#define fs const string&#define debug() puts("I Love Hina Forever")using namespace std ;namespace IO { template<class T>inline void read(T &x){char c=getchar(),f=false;x=0;while(c<48||c>57) {f|=(c==45),c=getchar();}while(c>=48&&c<=57){x=(x<<3)+(x<<1)+(c^48),c=getchar();}if(f){x=~x+1;}} template<class T,class ...Arg>inline void read(T &x,Arg &...arg){read(x),read(arg...);} template<class T>inline void write(T x){if(x<0){putchar(45),x=~x+1;}if(x>9){write(x/10);}putchar(x%10|48);} template<class T>inline void write(T x,fc c){write(x),putchar(c);}}using namespace IO ;const int P = 1e9 + 7,N = 305 ;int n,m,t ;ll A[N][N],D[N][N] ;#define mod(x) ((((x) %= P) += P) %= P)194 行未改动全部展开
注意对 $p$ 取模。
```cpp/*_/ _/ _/_/_/_/_/_/ _/ _/ _/_/_/ _/ _/ _/_/ _/ _/ _/_/ _/ _/ _/ _/ _/ _/ _/_/_/_/_/_/_/ _/ _/ _/ _/ _/ _/_/ _/ _/ _/ _/_/ _/_/_/_/_/_/_/ _/ _/ _/ _/ _/ _/_/ _/ _/_/_/_/_/_/ _/ _/ _/ _/*/#include<iostream>#include<cstdio>#define re register#define endl '\n'#define ll __int128#define ull unsigned long long#define db double#define fi const int&#define fl const ll&#define ful const ull&#define fc const char&#define fs const string&#define debug() puts("I Love Hina Forever")using namespace std ;namespace IO { template<class T>inline void read(T &x){char c=getchar(),f=false;x=0;while(c<48||c>57) {f|=(c==45),c=getchar();}while(c>=48&&c<=57){x=(x<<3)+(x<<1)+(c^48),c=getchar();}if(f){x=~x+1;}} template<class T,class ...Arg>inline void read(T &x,Arg &...arg){read(x),read(arg...);} template<class T>inline void write(T x){if(x<0){putchar(45),x=~x+1;}if(x>9){write(x/10);}putchar(x%10|48);} template<class T>inline void write(T x,fc c){write(x),putchar(c);}}using namespace IO ;ll n,m,p ;inline ll qpow (ll a,ll b) { ll ans = 1 ; while (b) {12 行未改动## [6. MarsOJ P2649. Expectation](https://marsoj.cn/p/P2649)
定义生成树的“权值”为所有边权的按位与。
求随即一颗生成树权值期望。求随机一颗生成树权值期望。
### 思路
首先总情况数即总生成树个数 $sum$。4 行未改动
期望 $p = \sum\limits_{i=1}^{base}\dfrac{now_i}{sum}\times 2^i$。
```cpp/*_/ _/ _/_/_/_/_/_/ _/ _/ _/_/_/ _/ _/ _/_/ _/ _/ _/_/ _/ _/ _/ _/ _/ _/ _/_/_/_/_/_/_/ _/ _/ _/ _/ _/ _/_/ _/ _/ _/ _/_/ _/_/_/_/_/_/_/ _/ _/ _/ _/ _/ _/_/ _/ _/_/_/_/_/_/ _/ _/ _/ _/*/#include<iostream>#include<cstdio>#include<cstring>#define re register#define endl '\n'#define ll long long#define ull unsigned long long#define db double#define fi const int&#define fl const ll&#define ful const ull&#define fc const char&#define fs const string&#define debug() puts("I Love Hina Forever")using namespace std ;namespace IO { template<class T>inline void read(T &x){char c=getchar(),f=false;x=0;while(c<48||c>57) {f|=(c==45),c=getchar();}while(c>=48&&c<=57){x=(x<<3)+(x<<1)+(c^48),c=getchar();}if(f){x=~x+1;}} template<class T,class ...Arg>inline void read(T &x,Arg &...arg){read(x),read(arg...);} template<class T>inline void write(T x){if(x<0){putchar(45),x=~x+1;}if(x>9){write(x/10);}putchar(x%10|48);} template<class T>inline void write(T x,fc c){write(x),putchar(c);}}using namespace IO ;const int N = 102,P = 998244353 ;int T,n,m ;ll K[N][N],sum,ans ;struct node {88 行未改动