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
  • 相关阅读:
    配置Mysql远程访问
    mysql Access denied for user root@localhost错误处理备忘
    MsSql判断表是否有自增标识
    .net用NPOI生成Word表格
    TensorFlow-卷积
    Java中int与Integer的区别
    由经纬度坐标得到腾讯地图的瓦片/切片行列号
    vs code上配置Scala
    VMware虚拟机上配置CentOS联网
    使用PuTTy在CentOS下安装web.py与简单的文件传输
  • 原文地址:https://www.cnblogs.com/zmin/p/8366096.html
Copyright © 2011-2022 走看看