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;
    }
  • 相关阅读:
    大话GridView—(1) 编辑、删除、查看详情、分页
    『协议』XMLRPC 协议规格说明
    『ExtJS』01 009. ExtJS 4 方法重载
    [SQL2005触发器学习]3、Instead Of触发器
    [SQL2005触发器学习]1、初识触发器
    禁止.NET程序多开
    面试遇到的面试题分析
    关于Page,Master,UserControl的初始化及加载顺序
    ASP.NET 下关于ACCESS连接字符串的配置
    [SQL2005触发器学习]2、After触发器
  • 原文地址:https://www.cnblogs.com/xxxsans/p/12730976.html
Copyright © 2011-2022 走看看