bzoj 4004: [JLOI2015]装备购买

本文介绍了一种使用高斯消元法求解线性基的问题,并通过引入逆元来解决系数增长问题。文章提供了一个具体的C++实现案例,包括排序、系数调整等关键步骤。

做了好多天了,,,写错勿喷(本来就不太会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 }

 

转载于:https://www.cnblogs.com/ccd2333/p/6481005.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值