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
  • 相关阅读:
    sql server 中将由逗号“,”分割的一个字符串,转换为一个表,并应用于 in 条件,方法和调用
    JavaScript Invalid Date Verify
    Jquery总结
    java中的异常和处理
    联系 管理 Hibernate4+Spring JPA+SpringMVC+Volecity搭建web应用(三)
    Hibernate4+Spring JPA+SpringMVC+Volecity搭建web应用(二)
    Hibernate4+Spring JPA+SpringMVC+Volecity搭建web应用(一)
    Spring 框架整理
    java 三大框架 介绍
    struts2 拦截器的注册在strut.xml中
  • 原文地址:https://www.cnblogs.com/zmin/p/8366096.html
Copyright © 2011-2022 走看看