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
  • 相关阅读:
    毕业设计同学们的福利(将word表格导入PowerDesigner中实现快速创建PDM)
    (转载)彻底的理解:WebService到底是什么?
    Aptana常用快捷键总结
    解决nuxt中路由变化后vanlist触底不加载的问题
    vuepropertydecorator的装饰器及其功能(可能不全)
    前端基础复习篇DOM
    Docker如何制作镜像Dockerfile的使用
    接口测试及常用接口测试工具
    SVN快速入门3——整合eclipse(1)
    SVN快速入门1——SVN的安装及常用命令
  • 原文地址:https://www.cnblogs.com/zmin/p/8366096.html
Copyright © 2011-2022 走看看