2018ACM山东省赛 Games(dp取数)
Games
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
#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取数)的更多相关文章
- P1005 矩阵取数游戏 区间dp 高精度
题目描述 帅帅经常跟同学玩一个矩阵取数游戏:对于一个给定的n \times mn×m的矩阵,矩阵中的每个元素a_{i,j}ai,j均为非负整数.游戏规则如下: 每次取数时须从每行各取走一个元素,共n ...
- NOIP2007矩阵取数[DP|高精度]
题目描述 帅帅经常跟同学玩一个矩阵取数游戏:对于一个给定的n*m的矩阵,矩阵中的每个元素aij均为非负整数.游戏规则如下: 1.每次取数时须从每行各取走一个元素,共n个.m次后取完矩阵所有元素: 2. ...
- Vijos1451圆环取数[环形DP|区间DP]
背景 小K攒足了路费来到了教主所在的宫殿门前,但是当小K要进去的时候,却发现了要与教主守护者进行一个特殊的游戏,只有取到了最大值才能进去Orz教主…… 描述 守护者拿出被划分为n个格子的一个圆环,每个 ...
- HDU 1565&1569 方格取数系列(状压DP或者最大流)
方格取数(2) Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- 1166 矩阵取数游戏[区间dp+高精度]
1166 矩阵取数游戏 2007年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description [ ...
- 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 -- ...
- 51Nod 1083 矩阵取数问题(矩阵取数dp,基础题)
1083 矩阵取数问题 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题 一个N*N矩阵中有不同的正整数,经过这个格子,就能获得相应价值的奖励,从左上走到右下,只能向下 ...
- 计蒜客 取数游戏 博弈+dp
题目链接 取数游戏 思路:dp(x, y)表示先手在区间[x, y]能取得的最大分数.当先手取完,就轮到后手去,后手一定会选择当前能令他得到最大分数的策略,其实当先手在[x, y]区间两端取走一个数, ...
- 矩阵取数问题(dp,高精)
题目描述 帅帅经常跟同学玩一个矩阵取数游戏:对于一个给定的n×mn \times mn×m的矩阵,矩阵中的每个元素ai,ja_{i,j}ai,j均为非负整数.游戏规则如下: 每次取数时须从每行各取走 ...
随机推荐
- SCRM从入门到精通01
[SCRM从入门到精通01]如何基于微信开放接口开发企业的微信CRM? 业内一直都在传说微信是天生的CRM,可是没有人看到过微信CRM的真容.随着微信最新公众平台的改版和开放接口的微信认证开放,微信C ...
- SQL Server 中 GO 的用法(转)
本科里学了那么多年SQL Server一直看到书上各种SQL语句中间夹杂着那么几个看似毫无意义的GO,看着就让人莫名,问老师,老师一般只会告诉你,不要理他,这个东西没用的.但是个性纠结并且有轻微强迫症 ...
- 连通性 保证f具有介值性质
- 【题解】数字组合(NTT+组合 滑稽)
[题解]数字组合(NTT+组合 滑稽) 今天实践一下谢总讲的宰牛刀233,滑稽. \((1+x)(1+x)(1+x)\)的\(x^2\)系数就代表了有三个一快钱硬币构成的两块钱的方案数量. 很好理解, ...
- MySql索引建立规则
为了使索引的使用效率更高,在创建索引时,必须考虑在哪些字段上创建索引和创建什么类型的索引.本小节将向读者介绍一些索引的设计原则. 1.选择唯一性索引 唯一性索引的值是唯一的,可以更快速的通过该索引来确 ...
- JS性能优化——DOM编程
浏览器中的DOM 天生就慢 DOM是个与语言无关的API,它在浏览器中的接口却是用JavaScript实现的.客户端脚本编程大多数时候是在个底层文档打交道,DOM就成为现在JavaScript编码中 ...
- C ~ 指针零散记录
2016.10.11 一个记录 void MB_float_u16(float f,uint16_t *a,uint16_t *b) { uint8_t *fp; ① uint8_t *ap; ② a ...
- [2018-05-27]配置VSTS认证方式使用Personal Access Token
本文介绍下如何配置VSTS(visual studio team service,其实就是微软SaaS版的TFS)通过Personal Access Token访问其下的Git代码库. 问题 使用gi ...
- JAVA各版本更新特性1-8
JAVA各版本更新特性1-8 原文地址 Java Versions, Features and History This article gives you a highlight of import ...
- ubuntu16.04下安装wordpress
安装过程 http://blog.topspeedsnail.com/archives/4635 http://blog.topspeedsnail.com/archives/4646 碰到的问题 1 ...