• hdu 5119 Happy Matt Friends


    http://acm.hdu.edu.cn/showproblem.php?pid=5119

    题意:有n个数,然后从中挑选任意多的数进行异或,问异或出的值大于等于M的方案数多少?

    思路:转移方程f[i][j]=f[i-1][j]+f[i-1][j^a[i]].  可以枚举这个值,对每个状态,来源有两个——一是上一个阶段不取,二是取a[i].

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <algorithm>
     4 #define ll long long
     5 #define maxn 50
     6 using namespace std;
     7 
     8 int t,n,m;
     9 int a[maxn];
    10 ll dp[50][(1<<20)+10];
    11 
    12 int main()
    13 {
    14     scanf("%d",&t);
    15     for(int cas=1; cas<=t; cas++)
    16     {
    17         scanf("%d%d",&n,&m);
    18         memset(dp,0,sizeof(dp));
    19         for(int i=1; i<=n; i++)
    20         {
    21             scanf("%d",&a[i]);
    22         }
    23         dp[0][0]=1;
    24         for(int i=1; i<=n; i++)
    25         {
    26             for(int j=0; j<(1<<20); j++)
    27             {
    28                 dp[i][j]=dp[i-1][j]+dp[i-1][j^a[i]];
    29             }
    30         }
    31         ll ans=0;
    32         for(int i=m; i<(1<<20); i++)
    33         {
    34             ans+=dp[n][i];
    35         }
    36         printf("Case #%d: %lld
    ",cas,ans);
    37     }
    38     return 0;
    39 }
    View Code
  • 相关阅读:
    2017 ICPC beijing E
    1629 B君的圆锥
    1298 圆与三角形
    通过String获取字符数组
    Java中的代码点与代码单元
    数据库事务隔离级别
    oracle修改密码、添加用户及授权
    Python起航
    软件测试常见概念
    TestNG--@Factory
  • 原文地址:https://www.cnblogs.com/fanminghui/p/4229722.html
Copyright © 2020-2023  润新知