题干:

Problem Description

Alice and Bob are playing a stone game. There are nnn piles of stones. In each turn, a player can remove some stones from a pile (the number must be positive and not greater than the number of remaining stones in the pile). One player wins if he or she remove the last stone and all piles are empty. Alice plays first.
To make this game even more interesting, they add a new rule: Bob can choose some piles and remove entire of them before the game starts. The number of removed piles is a nonnegative integer, and not greater than a given number ddd. Note ddd can be greater than nnn, and in that case you can remove all of the piles.
Let ansansans denote the different ways of removing piles such that Bob are able to win the game if both of the players play optimally. Bob wants you to calculate the remainder of ansansans divided by 109+710^9+7109+7.

Input

The first line contains an integer TTT, representing the number of test cases.
For each test cases, the first line are two integers nnn and ddd, which are described above.
The second line are nnn positive integers aia_iai​, representing the number of stones in each pile.
T≤5,n≤103,d≤10,ai≤103T \leq 5, n \leq 10^3, d \leq 10, a_i \leq 10^3T≤5,n≤103,d≤10,ai​≤103

Output

For each test case, output one integer (modulo 109+710^9 + 7109+7) in a single line, representing the number of different ways of removing piles that Bob can ensure his victory.

Sample Input

2
5 2
1 1 2 3 4
6 3
1 2 4 7 1 2 

Sample Output

2
5

题目大意:

剥去博弈的外皮,简化之后的题意是:给定n个数,一个x,让你最多可以选择d个数,求异或和为x的方案数。

解题报告:

直接dp就行了,用滚动数组空间优化掉一维。(方法和01背包一样倒着遍历)

AC代码:

//C
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<cctype>
using namespace std;
typedef long long ll;
const int MAX=1<<11;
const int mod=1e9+7;
//a=num[1]^num[2]^..^num[n];
//选i(0<=i<=d)个数使异或和等于a
//dp[i][d][v]从前i个数中选d个数, 异或和为v的方案数
//dp[i][d][v]=dp[i-1][d][v]+dp[i-1][d-1][v^val[i]];
int n,d,val[MAX+5];
ll dp[15][MAX+5]; //滚动减掉第一维
int main()
{int t,q,i,j,k,sum;ll ans=0;cin>>t;for(;t;t--){scanf("%d%d",&n,&d); d=min(d,n);ans=sum=0;for(i=1;i<=n;i++){scanf("%d",&val[i]);sum^=val[i];}//initfor(i=0;i<=d;i++){for(j=0;j<=MAX;j++)dp[i][j]=0;}dp[0][0]=1;for(i=1;i<=n;i++){for(j=d;j>=1;j--){for(k=0;k<=MAX;k++){dp[j][k]=(dp[j][k]+dp[j-1][k^val[i]])%mod;}}   }for(i=0;i<=d;i++)ans=(ans+dp[i][sum])%mod;printf("%lld\n",ans);}return 0;
}

【2018ACM山东省赛 - G】Games(Nim博弈 + dp)相关推荐

  1. 2018ACM四川省赛G.Grisaia(超棒的杜教筛好题)

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 G. Grisaia(灰色的果实好耶<灰色的果实(The Fruit of Grisaia)&g ...

  2. 【2018ACM山东省赛 - E】Sequence(树状数组,思维,优化)

    题干: We define an element aia_iai​ in a sequence "good", if and only if there exists a j(1≤ ...

  3. 【2018ACM山东省赛 - C】Cities(最小生成树变形优化,贪心思维)

    题干: Problem Description There are nnn cities in Byteland, and the ithi_{th}ith​ city has a value aia ...

  4. 【2018ACM山东省赛 - B】Bullet(二分 + 二分图匹配,匈牙利算法,卡常)

    题干: Problem Description In GGO, a world dominated by gun and steel, players are fighting for the hon ...

  5. [SPOJ IGAME Interesting Game]Nim 博弈+数位DP

    [SPOJ IGAME Interesting Game]Nim 博弈+数位DP 分类:博弈 数位DP 1. 题目链接 [SPOJ IGAME Interesting Game] 2. 题意描述 Al ...

  6. Nim博弈和威佐夫博弈 Return of the Nim

    Nim博弈 Nim游戏的概述: 还记得这个游戏吗? 给出n列珍珠,两人轮流取珍珠,每次在某一列中取至少1颗珍珠,但不能在两列中取.最后拿光珍珠的人输. 后来,在一份资料上看到,这种游戏称为" ...

  7. HDU 3590 PP and QQ(反nim博弈,删边游戏)

    PP and QQ 思路 删边游戏了解一下,其实就是个nim博弈吧,只是删边个数有特殊限制, 然后就是一个反nim博弈了. 删边定理: 遇到分叉口时,它的子树上的可操作的sg函数为所有子树节点的sg函 ...

  8. 2019ACM浪潮杯山东省赛参赛总结

    emmm是要记录一下生活了呢,不然以后退役了连自己经历过什么都记不住了. 5.11周六,早上5:30分,qdu集训队一行40人(左右)集合登上大巴,前往济南大学参加ACM省赛.上车清点了一下人数,然后 ...

  9. 牛客国庆集训派对Day3: G. Stones(博弈+SG)

    G. Stones 题目描述 有n堆石子,第i堆石子有xi个. 修修和栋栋轮流取石子,每人每次需要从任意一堆石子中取走个,修修先手.无法操作的人失败.此外,如果一个人取完了一堆石子,他会立即获胜. 不 ...

最新文章

  1. Java 领域 offer 收割:程序员黄金 5 年进阶心得!
  2. 静态移值编译的关键环境变量
  3. JRebel 代理激活
  4. 离线安装minikube—1.10.1
  5. BadI /ui2/catalog_provider_bd
  6. 面向中后台复杂场景的低代码实践思路
  7. ip地址配置 mongodb_MongoDB安全配置详解
  8. 网站对战服务器,PVP核心精华:三大服务器对战
  9. java 循环效率_Java For循环效率测试
  10. (已解决) centos6.5 yum源 失效 The whole CentOS 6 is dead and shouldn’t be used anywhere at all
  11. 设计实例_Python程序设计实例教程课后习题参考答案
  12. 计算机导论大一第四章,计算机导论-第四章.ppt
  13. 树莓派接入USB摄像头
  14. 进销存管理系统搭建流程
  15. 2020家用千兆路由器哪款好_什么路由器比较好(2020年最好千兆路由器)
  16. 006 管理Ceph的RBD块设备
  17. 极好的六个开源数据挖掘工具
  18. Spring MVC 参数校验
  19. 5G NR标准 第4章 LTE概述
  20. Java Study Notes_Design in 2023(Day01~Day14)

热门文章

  1. 动态规划几种状态剪裁比较
  2. leetcode之回溯backtracing专题3
  3. rmi远程代码执行漏洞_WebSphere 远程代码执行漏洞浅析(CVE20204450)
  4. Java设计模式笔记(5)建造者模式
  5. php 固话验证,收货地址参数校验:收货人、邮编、地址、手机、固话等
  6. export LD_LIBRARY_PATH 的使用
  7. 华北水利水电C 语言实验11,华北水利水电大学C语言实验11.doc
  8. gcovr 安装_Kudu 1.8.0 编译安装配置
  9. 【转】搞机:window10安装Linux子系统(WSL)及迁移到非系统盘
  10. 【转】GigE Vision简介