md有毒卡什么精度!!!!
最大线性无关组(线性基)可作为模板。
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #define eps 1e-5 #define maxn 550 #define double long double using namespace std; int n,m,ins[maxn],cnt=0,sum=0; struct pnt { double x[maxn]; int c; }p[maxn]; bool cmp(pnt x,pnt y) { return x.c<y.c; } int main() { scanf("%d%d",&n,&m); for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) scanf("%Lf",&p[i].x[j]); for (int i=1;i<=n;i++) scanf("%d",&p[i].c); sort(p+1,p+n+1,cmp); for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) { if (fabs(p[i].x[j])>eps) { if (ins[j]) { double r=p[i].x[j]/p[ins[j]].x[j]; for (int k=j;k<=m;k++) p[i].x[k]-=p[ins[j]].x[k]*r; } else { cnt++;sum+=p[i].c; ins[j]=i;break; } } } printf("%d %d\n",cnt,sum); return 0; }