虽然是一道还是算简单的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. [LeetCode]题解(python):096-Unique Binary Search Trees

    题目来源: https://leetcode.com/problems/unique-binary-search-trees/ 题意分析: 给定一个整数n,返回所有中序遍历是1到n的树的可能. 题目思 ...

  2. android开发环境安装记录

    首先进入http://developer.android.com/sdk/index.html, Google提供了一个新的DeveloperTools,即:ADT Bundle,中文翻译之:ADT捆 ...

  3. Windows Azure HDInsight 支持预览版 Hadoop 2.2 群集

     Windows Azure HDInsight 支持预览版 Hadoop 2.2 群集 继去年 10 月推出 Windows Azure HDInsight 之后,我们宣布 Windows Az ...

  4. BZOJ 1089 严格n元树 (递推+高精度)

    题解:用a[i]表<=i时有几种树满足度数要求,那么这样就可以递归了,a[i]=a[i-1]^n+1.n个节点每个有a[i-1]种情况,那么将其相乘,最后加上1,因为深度为0也算一种.那么答案就 ...

  5. HDU 3350 #define is unsafe

    题目大意:给定一个只含有MAX和+操作的式子,求加法运行了多少次,其中MAX使用宏定义. 题解:注意一个规律,对于MAX(A,B)其中A中加a次,B中加b次若A>B,则加a*2+b次,否则a+b ...

  6. 移动开发语言Swift

    苹果公布了全新的编程语言Swift,Swift继承了Objective-C语言特性,并从Python和Java Script中长处,使Swift更易读.未来swift编程语言的会特大广大的使用 Swi ...

  7. 发送Email并添加附件

    1. 添加命名空间 using System.Net.Mail; using System.Net; 2. The HTML MarpUp <html xmlns="http://ww ...

  8. exists

    select count(*) from Table_A where exists (select count(*) from Table_B.Column1 = Table_A.Column1) 该 ...

  9. [置顶] P2P之我见,关于打洞的学问-------开篇

    最近忙项目,有点累,无暇顾急博客,4月份本来想写写流媒体的文章,结果回家休了两个月回深圳后,接了P2P的项目,那就开始P2P吧. P2P起源于美国大学生Shawn Fanning 写的一个分享软件Na ...

  10. phpcms v9附件上传后显示链接名称如何改为附件名称?

    使用phpcms v9的朋友都知道,v9在后台添加内容的时候上传附件显示的是一个链接,这样太不人性化了,那怎么显示文件名称呢 ?小编以前发布文章的时候都是上传后复制链接在给文字加上超链接的,这样非常的 ...