BZOJ 4004: [JLOI2015]装备购买 [高斯消元同余 线性基]

和前两(一)题一样,不过不是异或方程组了.....

然后bzoj的新数据是用来卡精度的吧.....

所有只好在模意义下做啦

只是巨慢无比

 

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bitset>
using namespace std;
typedef long long ll;
const int N=505;
const int P=1e9+7;
inline int read(){
    char c=getchar();int x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
int n,m,c,ans,cnt;
double eps=1e-8;
struct Matrix{
    ll a[N];
    int c;
    ll& operator[](int x){return a[x];}
    bool operator <(const Matrix &r)const{return c<r.c;}
}a[N];
inline ll Pow(ll a,int b){
    ll re=1;
    for(;b;b>>=1,a=a*a%P)
        if(b&1) re=re*a%P;
    return re;
}
inline ll Inv(ll a){return Pow(a,P-2);}
bool check(Matrix &a){
    for(int i=1;i<=m;i++) if(a[i]) return true;
    return false;
}
int pivot[N];
void Gauss(){
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++) if(a[i][j]){
            if(pivot[j]){
                int pj=pivot[j];
                ll t=a[i][j]*Inv(a[pj][j])%P;
                for(int k=1;k<=m;k++) a[i][k]=(a[i][k]-t*a[pj][k]%P+P)%P;
            }else{pivot[j]=i;break;}
        }
        if(check(a[i])) ans+=a[i].c,cnt++;
    }
}
int main(){
    freopen("in","r",stdin);
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) a[i][j]=read();
    for(int i=1;i<=n;i++) a[i].c=read();
    sort(a+1,a+1+n);
    Gauss();
    printf("%d %d",cnt,ans);
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值