bzoj 4004: [JLOI2015]装备购买
做了好多天了,,,写错勿喷(本来就不太会2333)
用类似高斯消元的方法搞出线性基,当然要求最小肯定要先排一下序233,然后我记得看神犇们的博客的时候,这种高斯消元系数的增长是成指数式的,然后某机智的神犇取了逆元233333
(不记得神犇们的博客了,,(如有侵权,,,,,,,额,额,额,怎么办。。。。))
1 #include<bits/stdc++.h> 2 #define N 100005 3 #define LL long long 4 #define inf 0x3f3f3f3f 5 using namespace std; 6 inline int ra() 7 { 8 int x=0,f=1; char ch=getchar(); 9 while (ch<'0' || ch>'9') {if (ch=='-') f=-1; ch=getchar();} 10 while (ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();} 11 return x*f; 12 } 13 int n,m,vis[505],ans,cnt; 14 const int mod=998244353; 15 struct node{ 16 int v,f[505]; 17 bool operator < (const node &x) const {return v<x.v;} 18 }p[505]; 19 int ksm(int x, int p) 20 { 21 int sum=1; 22 for (;p;p>>=1,x=1LL*x*x%mod) 23 if (p&1) sum=1LL*sum*x%mod; 24 return sum; 25 } 26 int inv(int x) {return ksm(x,mod-2);} 27 int main() 28 { 29 n=ra(); m=ra(); 30 for (int i=1; i<=n; i++) 31 for (int j=1; j<=m; j++) 32 p[i].f[j]=ra(); 33 for (int i=1; i<=n; i++) p[i].v=ra(); 34 sort(p+1,p+n+1); 35 for (int i=1; i<=n; i++) 36 for (int j=1; j<=m; j++) 37 if (p[i].f[j]) 38 { 39 if (vis[j]) 40 { 41 int t=1LL*inv(p[vis[j]].f[j])*p[i].f[j]%mod; 42 for (int k=j; k<=m; k++) 43 { 44 p[i].f[k]-=1LL*t*p[vis[j]].f[k]%mod; 45 if (p[i].f[k]<0) p[i].f[k]+=mod; 46 } 47 } 48 else 49 { 50 cnt++; 51 vis[j]=i; 52 ans+=p[i].v; 53 break; 54 } 55 } 56 printf("%d %d",cnt,ans); 57 return 0; 58 }