[JLOI2015]装备购买

线性基+贪心

这题毒瘤在卡精度

在模质数意义下进行线性基可避免精度误差

#include"cstdio"
#include"cstring"
#include"iostream"
#include"algorithm"
#include"cmath"
using namespace std;

const int MAXN=505;
const int MOD=19260817;

int n,m,cnt,sum;
struct rpg{
	int v[MAXN],val;
}a[MAXN],lb[MAXN];

bool cmp(rpg a,rpg b){return a.val<b.val;}

int getinv(int x){return x==1?1:(long long)(MOD-MOD/x)*getinv(MOD%x)%MOD;}

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i){
		for(int j=1;j<=m;++j){
			scanf("%d",&a[i].v[j]);
		}
	}for(int i=1;i<=n;++i) scanf("%d",&a[i].val);
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;++i){
		for(int j=1;j<=m;++j){
			if(!a[i].v[j]) continue;
			if(!lb[j].val){lb[j]=a[i];lb[j].val=1;sum+=a[i].val;++cnt;break;}
			int tmp=(long long)a[i].v[j]*getinv(lb[j].v[j])%MOD;
			for(int k=m;k>=j;--k) a[i].v[k]-=(long long)lb[j].v[k]*tmp%MOD,a[i].v[k]%=MOD;
		}
	}printf("%d %d\n",cnt,sum);
	return 0;
}
posted @ 2019-02-17 07:31  A·H  阅读(135)  评论(0编辑  收藏  举报