虽然是一道还是算简单的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. ipc$爆破密码

    FOR /L %%i IN (1,1,99) DO net use \\192.168.1.1\ipc$ /user:test %%i && echo %%i>1.txt

  2. C——货物管理系统

    #include <stdio.h> #include <stdlib.h> #include <string.h> #include <conio.h> ...

  3. 高质量程序设计指南C/C++语言——C++/C程序设计入门(4)

    *switch结构的break语句只是一个“jmp”指令,其作用就是跳到switch结构的结尾处 *标准C++/C语言提供3种循环:do/while.while和for,它们都在条件表达式为TRUE( ...

  4. sping+maven+mybatis+ehcache续之实现mapper

    配置接着上一篇文章 新建UserMapper.java和UserMapper.xml 其中UserMapper.xml的namespace以及文件名要和UserMapper.java一致 <ma ...

  5. Vim键盘布局

     Vim键盘布局 用Linux的朋友一定会使用到Vim这个文本编辑器,它是由Vi发展而来的编辑器,其具有代码补齐.编译.错误跳转等丰富的功能,非常适合编程.对于修改Linux配置文件它更是你不二的选择 ...

  6. protel99se中做拼板图解

    很多时候我们要在protel99se中做拼板, 但是通常在复制进行拼版的时候会出现如下的效果,元件被重新命名了. 而无法达到我们需要的像下图的效果 那我们怎么办,才能达到上图的效果呢?其实操作很简单. ...

  7. 从Xib文件加载UIView的5种方式

    在不同的Xib文件中最容易维护的是定义的视图,因此对于从Xib文件中加载UIView来说一个方便的流程是非常重要. 在过去的几年里我发现唯一易于管理创建和维护视图(或者任何界面元素,通常会更多)方式就 ...

  8. Curling 2.0(dfs回溯)

    Curling 2.0 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15567   Accepted: 6434 Desc ...

  9. 【转】Ubuntu常用软件合集

    [转]Ubuntu常用软件合集 Ubuntu常用软件合集 我用的使Ubuntu-Kylin14.04,原因呢主要是觉得使本土化的,自带了日历.输入法.优客助手等易于上手的应用.也省的每次安装完原生的系 ...

  10. 【转】KVM/Installation

    [转]KVM/Installation Installation Pre-installation checklist Check that your CPU supports hardware vi ...