虽然是一道还是算简单的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. Spring Boot Admin Reference Guide

    1. What is Spring Boot Admin? Spring Boot Admin is a simple application to manage and monitor your S ...

  2. 数据结构- 串的模式匹配算法:BF和 KMP算法

      数据结构- 串的模式匹配算法:BF和 KMP算法  Brute-Force算法的思想 1.BF(Brute-Force)算法 Brute-Force算法的基本思想是: 1) 从目标串s 的第一个字 ...

  3. VC编程之设置客户区背景图片

    在很多系统中出于美观的需要常常要设置背景图片.下面我介绍一种在客户区设置背景图片的简单方法. 1 .将背景bmp 图片导入到工程,资源ID 这里假设为 IDB_BITMAP1 2 .在视图类添加如下代 ...

  4. uva11536 Smallest Sub-Array

    Thinking about it: 我的思路跟sliding window有点类似.假设已经确定了一个区间[l, r],序列中从 l 到 r 恰好包含了[1, K]的各个元素,则从 r 开始继续迭代 ...

  5. Libev学习笔记2

    这一节根据官方文档给出的简单示例,深入代码内部,了解其实现机制.示例代码如下: int main (void) { struct ev_loop *loop = EV_DEFAULT; ev_io_i ...

  6. OpenStack_Swift源代码分析——Object-auditor源代码分析(1)

    1 Object-auditor 的启动 Object-auditor的启动和object-replicator的启动过程是一样的,首先是运行启动脚本 swift-init object-audito ...

  7. SRM 585

    250 : 递推,从左下角到右下角走一条,剩下的都是子结构 const int mod = 1000000007; long long dp[1000010] , s[1000010]; class ...

  8. Visual Studio warning MSB3270:There was a mismatch between the processor architecture of the project being built "MSIL"

    Problem: There was a mismatch between the processor architecture of the project being built "MS ...

  9. URAL 1260 Nudnik Photographer DFS DP

    题目:click here :这个题可以先dfs深搜下,规律dp dfs: #include <bits/stdc++.h> using namespace std; #define S ...

  10. Definitions

    Definitions and ODR Definitions are declarations that fully define the entity introduced by the decl ...