zoukankan      html  css  js  c++  java
  • Happy Matt Friends HDU 5119 [计数DP]

    Matt has N friends. They are playing a game together. 

    Each of Matt’s friends has a magic number. In the game, Matt selects some (could be zero) of his friends. If the xor (exclusive-or) sum of the selected friends’magic numbers is no less than M , Matt wins. 

    Matt wants to know the number of ways to win.

    InputThe first line contains only one integer T , which indicates the number of test cases. 

    For each test case, the first line contains two integers N, M (1 ≤ N ≤ 40, 0 ≤ M ≤ 10 6). 

    In the second line, there are N integers ki (0 ≤ k i ≤ 10 6), indicating the i-th friend’s magic number.OutputFor each test case, output a single line “Case #x: y”, where x is the case number (starting from 1) and y indicates the number of ways where Matt can win.Sample Input

    2
    3 2
    1 2 3
    3 3
    1 2 3

    Sample Output

    Case #1: 4
    Case #2: 2
    

    Hint

    In the first sample, Matt can win by selecting:
    friend with number 1 and friend with number 2. The xor sum is 3.
    friend with number 1 and friend with number 3. The xor sum is 2.
    friend with number 2. The xor sum is 2.
    friend with number 3. The xor sum is 3. Hence, the answer is 4.
    这道题。。。mx=1e6WA,mx=1e7TLE,换成1<<20(比1e6大一点)就AC了
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const ll inf = 4e18+10;
    const int mod = 1000000007;
    const int mx = 1<<20; //check the limits, dummy
    typedef pair<int, int> pa;
    const double PI = acos(-1);
    ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
    #define swa(a,b) a^=b^=a^=b
    #define re(i,a,b) for(int i=(a),_=(b);i<_;i++)
    #define rb(i,a,b) for(int i=(b),_=(a);i>=_;i--)
    #define clr(a) memset(a, 0, sizeof(a))
    #define lowbit(x) ((x)&(x-1))
    #define mkp make_pair
    void sc(int& x) { scanf("%d", &x); }void sc(int64_t& x) { scanf("%lld", &x); }void sc(double& x) { scanf("%lf", &x); }void sc(char& x) { scanf(" %c", &x); }void sc(char* x) { scanf("%s", x); }
    ll dp[3][mx];
    int n, m, l, r,t,num[45];
    int main()
    {
        ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
        int cas = 1;
        cin >> t;
        while (t--){
            cin >> n >> m;
            re(i, 1, n + 1)cin >> num[i];
            clr(dp);
            dp[0][0] = 1;
            re(i, 1, n + 1)re(j, 0, mx - 5)dp[i % 2][j] = max(dp[i % 2][j], dp[(i - 1) % 2][j ^ num[i]] + dp[(i - 1) % 2][j]);
            ll ans = 0;
            re(i, m, mx - 5)ans += dp[n % 2][i];
            cout << "Case #" << cas++ << ':' <<' '<< ans << endl;
        }
        return 0;
    }
  • 相关阅读:
    POJ 1637:Sightseeing tour
    bzoj 3997: [TJOI2015]组合数学
    [CEOI2008]order
    【网络流24题】星际转移问题
    Codeforces Round #460 D. Karen and Cards
    bzoj 3142: [Hnoi2013]数列
    codeforces586B
    codeforces631B
    codeforces548B
    codeforces515B
  • 原文地址:https://www.cnblogs.com/xxxsans/p/12730976.html
Copyright © 2011-2022 走看看