当前位置:网站首页>P3265 [jloi2015] equipment purchase

P3265 [jloi2015] equipment purchase

2022-07-05 06:19:00 Strezia

Link
Real linear basis

#define double long double
double a[N][N];
struct node {
    
    double a[550];
    int w;
    bool operator < (const node &x) const {
    
        return w < x.w;
    }
}p[550];
int n, m;
double b[N][N];
bool insert(int m, double c[]) {
    
    for(int i = m-1; i >= 0; i--) {
    
        if(fabs(c[i]) < EPS) continue;
        if(fabs(b[i][i]) < EPS) {
    
            for(int j = 0; j < m; j++)
                b[i][j] = c[j];
            return true;
        }
        double t = c[i]/b[i][i];
        for(int j = 0; j < m; j++)
            if(fabs(c[i]) > EPS)
                c[j] -= b[i][j] * t;
    }
    return false;
}
void solve() {
    
    cin >> n >> m;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++)
            cin >> p[i].a[j];
    for(int i = 0; i < n; i++)
    {
    
        cin >> p[i].w;
        p[i].a[m] = p[i].w;
    }
    sort(p, p + n);
    int cnt = 0, res = 0;
    for(int i = 0; i < n; i++) {
    
        if(insert(m, p[i].a)) {
    
            cnt++;
            res += p[i].w;
        }
    }
    cout << cnt << ' ' << res << endl;
}
原网站

版权声明
本文为[Strezia]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140616367333.html