虽然是一道还是算简单的DP,甚至不用滚动数组也能AC,数据量不算很大。

对于N个数,每个数只存在两个状态,取 和 不取。

容易得出状态转移方程:

dp[i][j] = dp[i - 1][j ^ a[i]] + dp[i - 1][j];

dp[i][j] 的意思是,对于数列 中前 i 个数字,使得 XOR 和恰好为 j 的方案数

状态转移方程中的 dp[i - 1][j] 即表示当前这个数字不取, dp[i - 1][j ^ a[i]] 表示当前这个数字要取。

这道题还是要好好理解阿!

source code :

//#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#define ll long long
#define Max(a,b) (((a) > (b)) ? (a) : (b))
#define Min(a,b) (((a) < (b)) ? (a) : (b))
#define Abs(x) (((x) > 0) ? (x) : (-(x))) using namespace std; const int INF = 0x3f3f3f3f; int dp[][ << ];
int a[]; int main(){
int i, j, k, T, n, m, numCase = ;
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);
for(i = ; i <= n; ++i) scanf("%d", a + i);
memset(dp, , sizeof(dp));
dp[][] = ;
for(i = ; i <= n; ++i){
for(j = ; j < ( << ); ++j){
dp[i % ][j] = dp[(i - ) % ][j ^ a[i]] + dp[(i - ) % ][j];
}
}
long long ans = ;
for(i = m; i < ( << ); ++i){
ans += dp[n % ][i];
}
printf("Case #%d: %I64d\n",++numCase, ans);
}
return ;
}

HDU 5119 Happy Matt Friends(2014北京区域赛现场赛H题 裸背包DP)的更多相关文章

  1. HDU 5119 Happy Matt Friends (14北京区域赛 类背包dp)

    Happy Matt Friends Time Limit: 6000/6000 MS (Java/Others)    Memory Limit: 510000/510000 K (Java/Oth ...

  2. HDU 5119 Happy Matt Friends (背包DP + 滚动数组)

    题目链接:HDU 5119 Problem Description Matt has N friends. They are playing a game together. Each of Matt ...

  3. HDU 4800/zoj 3735 Josephina and RPG 2013 长沙现场赛J题

    第一年参加现场赛,比赛的时候就A了这一道,基本全场都A的签到题竟然A不出来,结果题目重现的时候1A,好受打击 ORZ..... 题目链接:http://acm.hdu.edu.cn/showprobl ...

  4. HDU 4815 Little Tiger vs. Deep Monkey 2013 长春现场赛C题

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=4815 [题意] n个题目,每题有各自的分数,A有50%的概率答对一道题目得到相应分数,B想要在至少P的概率 ...

  5. HDU 5122 K.Bro Sorting(2014北京区域赛现场赛K题 模拟)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5122 解题报告:定义一种排序算法,每一轮可以随机找一个数,把这个数与后面的比这个数小的交换,一直往后判 ...

  6. HDU 5119 Happy Matt Friends(递推)

    http://acm.hdu.edu.cn/showproblem.php?pid=5119 题意:给出n个数和一个上限m,求从这n个数里取任意个数做异或运算,最后的结果不小于m有多少种取法. 思路: ...

  7. HDU 5119 Happy Matt Friends

    Happy Matt Friends Time Limit: 6000/6000 MS (Java/Others) Memory Limit: 510000/510000 K (Java/Others ...

  8. 水题:HDU 5119 Happy Matt Friends

    Matt has N friends. They are playing a game together.Each of Matt's friends has a magic number. In t ...

  9. 2014 北京区域赛 dp

    Matt has N friends. They are playing a game together. Each of Matt’s friends has a magic number. In ...

随机推荐

  1. hdu 3333 Turing Tree

    题目链接 给n个数, m个询问, 每次询问输出区间内的数的和, 相同的数只计算一次. 数组里的数是>-1e9 <1e9, 可以把它离散以后用莫队搞... #include <iost ...

  2. 64位系统未注册"MSDAORA.1"提供程序

    原因:如错误,64位系统未注册"MSDAORA.1"提供程序 解决:在IIS应用程序池中找到自己的网站,打开高级设置,设置“启用32位应用程序”为“True”即可. 另外还有其他解 ...

  3. my.ini配置

    在家里写点东西,需要配置mysql windows版本,linux版本我一般都是直接编译后,有模板文件可以编辑,新下载的5.6没有,我用的是zip的. 在网上找了两篇博客,写的很详细: http:// ...

  4. 在TreeWidget中增加右键菜单功能 以及TreeWidget的基本用法

    TreeWidget 与 TreeView 中实现右键菜单稍有不同, TreeView 中是靠信号与槽 connect(ui->treeView,SIGNAL(customContextMenu ...

  5. 【Untiy3D 游戏开发之一】Unity3D For Window/Mac最新4.2.0版本破解教程

    转载请标明:转载自[小枫栏目],博文链接:http://blog.csdn.net/rexuefengye/article/details/11646885 一.Unity3D For Mac 1.首 ...

  6. Pascal向C++的跨越

    最近从pas转向了C++,觉得需要在语言上总结对比一下,以及记录一些注意点,关于STL,还需要之后好好地学习.同时,希望这篇文章对从pas转C++的同学有所帮助. 基本类型 首先是基本类型的比较: P ...

  7. HDU 2227 Find the nondecreasing subsequences

    题目大意:给定一个序列,求出其所有的上升子序列. 题解:一开始我以为是动态规划,后来发现离散后树状数组很好做,首先,c保存的是第i位上升子系列有几个,那么树状数组的sum就直接是现在的答案了,不过更新 ...

  8. File,FileInputStream,FileReader,InputStreamReader,BufferedReader 的使用和区别

    1 ) File 类介绍 File 类封装了对用户机器的文件系统进行操作的功能.例如,可以用 File 类获得文件上次修改的时间移动, 或者对文件进行删除.重命名.换句话说,流类关注的是文件内容,而 ...

  9. Tree(未解决。。。)

    Tree Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

  10. poj 3335 Rotating Scoreboard - 半平面交

    /* poj 3335 Rotating Scoreboard - 半平面交 点是顺时针给出的 */ #include <stdio.h> #include<math.h> c ...