Games

Time Limit: 1000 ms Memory Limit: 65536 KiB

Problem Description

Alice and Bob are playing a stone game. There are nn 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 dd. Note dd can be greater than nn, and in that case you can remove all of the piles.
Let ansans 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 ansans divided by 10^9+7109+7.

Input

The first line contains an integer TT, representing the number of test cases.
For each test cases, the first line are two integers nn and dd, which are described above.
The second line are nn positive integers a_iai​, representing the number of stones in each pile.
T \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 10^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

Hint

 

Source

“浪潮杯”山东省第九届ACM大学生程序设计竞赛(感谢山东财经大学)
 
 
 
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define MAX 1005
#define MOD 1000000007
using namespace std;
typedef long long ll; int a[MAX];
int dp[MAX][][]; int main()
{
int t,n,d,i,j,k;
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&d);
int sum=;
for(i=;i<=n;i++){
scanf("%d",&a[i]);
sum^=a[i];
}
for(i=;i<=n;i++){
dp[i][][]=;
}
for(i=;i<=n;i++){
for(j=;j<=d;j++){
for(k=;k<;k++){
dp[i][j][k]=dp[i-][j][k]+dp[i-][j-][k^a[i]];
dp[i][j][k]%=MOD;
}
}
}
ll ans=;
for(i=;i<=d;i++){
ans+=dp[n][i][sum];
ans%=MOD;
}
printf("%lld\n",ans);
}
return ;
}

2018ACM山东省赛 Games(dp取数)的更多相关文章

  1. P1005 矩阵取数游戏 区间dp 高精度

    题目描述 帅帅经常跟同学玩一个矩阵取数游戏:对于一个给定的n \times mn×m的矩阵,矩阵中的每个元素a_{i,j}ai,j​均为非负整数.游戏规则如下: 每次取数时须从每行各取走一个元素,共n ...

  2. NOIP2007矩阵取数[DP|高精度]

    题目描述 帅帅经常跟同学玩一个矩阵取数游戏:对于一个给定的n*m的矩阵,矩阵中的每个元素aij均为非负整数.游戏规则如下: 1.每次取数时须从每行各取走一个元素,共n个.m次后取完矩阵所有元素: 2. ...

  3. Vijos1451圆环取数[环形DP|区间DP]

    背景 小K攒足了路费来到了教主所在的宫殿门前,但是当小K要进去的时候,却发现了要与教主守护者进行一个特殊的游戏,只有取到了最大值才能进去Orz教主…… 描述 守护者拿出被划分为n个格子的一个圆环,每个 ...

  4. HDU 1565&1569 方格取数系列(状压DP或者最大流)

    方格取数(2) Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  5. 1166 矩阵取数游戏[区间dp+高精度]

    1166 矩阵取数游戏 2007年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description [ ...

  6. BZOJ 1978: [BeiJing2010]取数游戏 game( dp )

    dp(x)表示前x个的最大值,  Max(x)表示含有因数x的dp最大值. 然后对第x个数a[x], 分解质因数然后dp(x) = max{Max(t)} + 1, t是x的因数且t>=L -- ...

  7. 51Nod 1083 矩阵取数问题(矩阵取数dp,基础题)

    1083 矩阵取数问题 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题 一个N*N矩阵中有不同的正整数,经过这个格子,就能获得相应价值的奖励,从左上走到右下,只能向下 ...

  8. 计蒜客 取数游戏 博弈+dp

    题目链接 取数游戏 思路:dp(x, y)表示先手在区间[x, y]能取得的最大分数.当先手取完,就轮到后手去,后手一定会选择当前能令他得到最大分数的策略,其实当先手在[x, y]区间两端取走一个数, ...

  9. 矩阵取数问题(dp,高精)

    题目描述 帅帅经常跟同学玩一个矩阵取数游戏:对于一个给定的n×mn \times mn×m的矩阵,矩阵中的每个元素ai,ja_{i,j}ai,j​均为非负整数.游戏规则如下: 每次取数时须从每行各取走 ...

随机推荐

  1. ajax学习笔记(3)--$.get()方法

    <head runat="server"> <title>jQuery中的$.get()方法</title> <script src=&q ...

  2. 性能测试--Jmeter之wordpress示例

    Jmeter之wordpress示例 WordPress是使用PHP语言开发的博客平台,用户可以在支持PHP和MySQL数据库的服务器上架设属于自己的网站.也可以把 WordPress当作一个内容管理 ...

  3. 洛谷 2868 [USACO07DEC]观光奶牛Sightseeing Cows

    题目戳这里 一句话题意 L个点,P条有向边,求图中最大比率环(权值(Fun)与长度(Tim)的比率最大的环). Solution 巨说这是0/1分数规划. 话说 0/1分数规划 是真的难,但貌似有一些 ...

  4. MySQL基于二进制日志的主从复制

    一.什么是MySQL的主从复制? MySQL可以将一个数据库设置为主库,另一个数据库设置为该主库的从库,当主库发生了变更,会同步到从库中.MySQL的主从架构,可以是星型的,也可以是线型的. 星型架构 ...

  5. python获取当前的时间

    打印出当前的年月日时分秒 print(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))) 2018-09-05 09:39: ...

  6. 剑指Offer:字符串排列【38】

    剑指Offer:字符串排列[38] 题目描述 输入一个字符串,按字典序打印出该字符串中字符的所有排列.例如输入字符串abc,则打印出由字符a,b,c所能排列出来的所有字符串abc,acb,bac,bc ...

  7. uploadify 报错 超过了最大请求长度

    今天系统遇到了一个问题,上传4m以上的文件,uploadify就会报错:超过了最大请求长度. 开始我以为是设置的大小,可是后来我看了uploadify的fileSizeLimit=1024*10,也就 ...

  8. Linux2.4文件系统中vfsmount、安装点的dentry、设备的dentry之间的关系【转】

    本文转载自:https://blog.csdn.net/mishifangxiangdefeng/article/details/7566575 1.vfsmount.安装点的dentry.设备的de ...

  9. [转]aliyun阿里云Maven仓库地址——加速你的maven构建

    原文链接:http://www.cnblogs.com/geektown/p/5705405.html maven仓库用过的人都知道,国内有多么的悲催.还好有比较好用的镜像可以使用,尽快记录下来.速度 ...

  10. win下发现两个有用的快捷键

    调出命令行工具:win+x然后a.默认是cmd的管理员模式,可以改成powershell. 从当前目录打开命令行:shift + 鼠标右键