题目链接:

  http://acm.hdu.edu.cn/showproblem.php?pid=5119

题目:

题意:

  求选择任意个数,使其异或和大于等于m的方案数。

思路:

  每个数有选和不选两种方案,显然是背包思想。dp[i][j]表示前i个物品异或和为j时的方案数,转移方程为dp[i][j] = dp[i-1][j] + dp[i-1][j^a[i]]。这题可以考虑用滚动数组滚动掉一维,当然了,不滚动也是可以过滴~

代码实现如下:

 #include <set>
#include <map>
#include <deque>
#include <ctime>
#include <stack>
#include <cmath>
#include <queue>
#include <string>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; typedef long long LL;
typedef pair<LL, LL> pll;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef unsigned long long uLL; #define lson rt<<1
#define rson rt<<1|1
#define name2str(name)(#name)
#define bug printf("**********\n");
#define IO ios::sync_with_stdio(false);
#define debug(x) cout<<#x<<"=["<<x<<"]"<<endl;
#define FIN freopen("/home/dillonh/CLionProjects/in.txt","r",stdin); const double eps = 1e-;
const int maxn = (<<) + ;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const LL INF = 0x3f3f3f3f3f3f3f3fLL; int t, n, m;
int a[], dp[][maxn]; int main() {
#ifndef ONLINE_JUDGE
FIN;
#endif
int icase = ;
scanf("%d", &t);
while(t--) {
scanf("%d%d", &n, &m);
int mx = , cnt = ;
for(int i = ; i <= n; i++) scanf("%d", &a[i]), mx = max(mx, a[i]);
memset(dp, , sizeof(dp));
dp[][] = ;
while(mx) cnt++,mx >>= ;
for(int i = ; i <= n; i++) {
for(int j = ; j <= (<<cnt); j++) {
dp[i&][j] = dp[(i-)&][j] + dp[(i-)&][j^a[i]];
}
}
LL ans = ;
for(int i = m; i < maxn; i++) ans += dp[n&][i];
printf("Case #%d: %lld\n", ++icase, ans);
}
return ;
}

最新文章

  1. jarsigner签名报错Invalid keystore format
  2. request 和response
  3. # TypeScript 中如何确保 this 的正确性
  4. FIO使用指南
  5. jquery 更换皮肤
  6. BZOJ 2049: [Sdoi2008]Cave 洞穴勘测 LCT
  7. JavaScripts学习日记——BOM
  8. YACC基本用法
  9. DOS头分析
  10. 微信小程序开发心得--动画机制
  11. Android hybrid App项目构建和部分基本开发问题
  12. 微信小程序之自定义select下拉选项框组件
  13. day04 运算符 流程控制 (if while/of)
  14. 【交换机】交换机RLDP(环路检测&amp;链路检测)功能介绍及配置说明
  15. 小学四则运算APP 第三阶段冲刺-第一天
  16. android ListView 分页加载数据
  17. asp.net 多线程
  18. django url 中的namespace详解
  19. 消息队列的创建与读写ftok,msgget,msgsnd,msgrcv,指令ipcs,ipcrm 查看,删除消息队列
  20. js中常用的事件

热门文章

  1. 简单说明webbench的安装和使用
  2. No module named &#39;MySQLdb&#39; python3.6 + django 1.10 + mysql 无法连接
  3. Educational Codeforces Round 56 Div. 2 翻车记
  4. Spring Security OAuth 个性化token
  5. BZOJ1443 [JSOI2009]游戏Game 【博弈论 + 二分图匹配】
  6. 我们为什么要迁移PHP到HHVM
  7. Java EE之JSTL(下)
  8. Android之断点续传下载(转)
  9. python之旅:常用模块
  10. strut2以及路径的一些问题