虽然是一道还是算简单的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. 微信上传素材返回 '{"errcode":41005,"errmsg":"media data missing"}',php5.6返回

    问题描述: php5.5已经把通过@加文件路径上传文件的方式给放入到Deprecated中了.php5.6默认是不支持这种方式了 解决办法curl处理 function curl_post($url, ...

  2. [LeetCode]题解(python):117-Populating Next Right Pointers in Each Node II

    题目来源: https://leetcode.com/problems/populating-next-right-pointers-in-each-node-ii/ 题意分析: 根据上一题,如果给定 ...

  3. Sublime 编辑器主题

    Sublime主题分为两种 一种是编辑框中的代码的颜色  另一种是编辑器本身的颜色(不只是颜色哟  Sublime编辑器左边侧边栏的字很小对不对 !有了主题就可以改) 这个主题叫做Soda  http ...

  4. Java多线程编程中Future模式的详解

    Java多线程编程中,常用的多线程设计模式包括:Future模式.Master-Worker模式.Guarded Suspeionsion模式.不变模式和生产者-消费者模式等.这篇文章主要讲述Futu ...

  5. Hello China操作系统STM32移植指南(二)

    移植步骤详解 下面就以MDK 4.72为开发环境,详细说明Hello China内核向STM32的移植过程.MDK 4.72评估版只支持32K代码的编译,这对Hello China的内核来说,裁剪掉一 ...

  6. c 计算Fibonacci数列:1,1,2,3,5,8,13……这题也是很经典。

    输出数字序列2/,/,/,/,/,/...,输出个数由键盘输入.注意输入使用scanf输入 比如: 输入 3输出为 / / / 输入 输出为 / / / / #include<stdio.h&g ...

  7. Extending your SharePoint 2007 site with Microsoft ASP.NET AJAX 3.5

    After ASP.NET 3.5 has been installed you need to modify the web.config file of your MOSS web site wi ...

  8. BZOJ 2463 谁能赢呢?

           刚开始做这道题时,我纠结了许久什么是最优走法,想了好半天也不晓得,后来被大神点醒,最有走法,最后就是每个格子都走了一遍,得,这下简单多了,算一下总共的格数是奇数还是偶数,奇数则先手赢,偶 ...

  9. eclipse打war包

    链接地址:http://jingyan.baidu.com/article/c910274be14164cd361d2ddc.html 一个程序要想放到服务器容器中很多人想到了打一个war包放到tom ...

  10. JBPM6教程

    JBPM6教程-手把手教你安装JBPM 1. 安装JBPM的先决条件: (1)JDK 1.6+以上,没有安装的话,猛击这里. (2)Ant 1.7+以上,没有安装的话,看看这里. 2. 下载JBPM安 ...