• 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;
    }
  • 相关阅读:
    Cola:一个分布式爬虫框架
    MichaelBoselowitz/pygit2-examples: Examples of some "porcelain" git commands implemented with python bindings (pygit2) to the libgit2 library.
    https://github.com/mlzboy/spider-impl.git
    Installation and Status — CFFI 1.5.2 documentation
    CENTOS 6.5 安装 Python 2.7 总结
    CENTOS 6.5 安装 Python 2.7 总结
    Create a commit using pygit2
    Create a commit using pygit2
    Create a commit using pygit2
    LindDotNetCore~docker里图像上生成中文乱码问题
  • 原文地址:https://www.cnblogs.com/xxxsans/p/12730976.html
Copyright © 2020-2023  润新知