zoukankan      html  css  js  c++  java
  • HDU

    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.
    
            
     这题确实没想到是冒泡。
    另外注意数组开的时候小心点,在如果for循环1<<20 到1<<21的话,会越界。(因为是异或
    还有就是最后答案会爆int(这个应该都能注意到
    果然dp这方面自己还是只会模板,改改就蒙了。
     1 #include <cstdio>
     2 #include <cstring>
     3 #include <iostream>
     4 #include <algorithm>
     5 #include <iomanip>
     6 #include <cmath>
     7 using namespace std;
     8 typedef long long ll;
     9 const int maxn = 1<<20;
    10 int nu[maxn];
    11 int dp[41][maxn+10];
    12 int main()
    13 {
    14     ios::sync_with_stdio(false);
    15     int t,n,m;
    16   //  cout<<setiosflags(ios::fixed)<<setprecision(6);
    17     cin>>t;
    18     for(int cas=1;cas<=t;++cas)
    19     {
    20         cin>>n>>m;
    21         for(int i=1;i<=n;++i)
    22             cin>>nu[i];
    23         memset(dp,0,sizeof(dp));
    24         dp[0][0]=1;
    25         for(int i=1;i<=n;++i)
    26         {
    27             for(int j=0;j<maxn;++j)
    28             {
    29                 dp[i][j]=dp[i-1][j]+dp[i-1][j^nu[i]];
    30             }
    31         }
    32         ll ans=0;
    33         
    34         for(int i=m;i<maxn;++i)
    35             ans+=dp[n][i];
    36         cout<<"Case #"<<cas<<": "<<ans<<endl;
    37     }
    38     return 0;
    39 }
    View Code
  • 相关阅读:
    appium知识01-环境设置
    移动端测试基础知识02
    魔术方法和反射
    面向对象开发: 封装, 继承, 多态
    正则的用法
    内置方法, 第三方模块(math, random, pickle, json, time, os, shutil, zip, tarfile), 导入包
    推导式(列表, 集合, 字典), 生成器
    迭代器, 高阶函数(map, filter, reduce, sorted) , 递归函数
    函数globals和locals用法, LEGB原则, 闭包函数 , 匿名函数
    字符串, 列表, 元祖, 集合, 字典的相关操作和函数, 深浅copy
  • 原文地址:https://www.cnblogs.com/zmin/p/8366096.html
Copyright © 2011-2022 走看看