P4570 [BJWC2011] element (linear-yl)

The meaning of problems: n stones each stone has a, b two properties

   It requires that a selected some of the stones is not a subset of the attribute xor and b is 0 and the maximum properties and

Solution: linear base like example of the need to understand the nature ..

   1. prosequence may have in any of a number of groups obtained by the linear xor

   2. Linear Kiri number of linearly independent and is not a subset of xor and 0 (just meet on the meaning of the questions

   3. Linear yl premise of ensuring a size of the number of properties is minimal

   

   So the question put b property descending order greedy if this number can even insert a contribution

   If a number is inserted so that he does not come in and come in before the insertion of the number of linearly related to the number so than before so he will certainly be in front of the big number

   Then there will not be inserted to a large number of A results in a smaller two B, C, but does not come inserted B + C in this case b property is greater than A and is selected from A back

   If so, the instructions may be A, C to the linear case represented by B then you obviously can remove B, C which a point associated with A linear then put to A

   Such a linear configuration so that the bases are definitely superior to a large number of interpolation can be inserted

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

struct node{
    ll a;
    int b;
}e[1005];
bool cmp(node A, node B) {
    return A.b > B.b;
}
ll val[70];

int main() {
    int n;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) scanf("%lld%d", &e[i].a, &e[i].b);
    sort(e + 1, e + 1 + n, cmp);

    int ans = 0;
    for(int i = 1; i <= n; i++) {
        ll tmp = e[i].a;
        for(int j = 60; j >= 0; j--) {
            if(tmp & (1LL << j)) {
                if(!val[j]) {
                    ans += e[i].b;
                    val[j] = tmp;
                    break;
                }
                tmp ^= val[j];
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}
View Code

 

Guess you like

Origin www.cnblogs.com/lwqq3/p/11432837.html