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均为非负整数.游戏规则如下: 每次取数时须从每行各取走 ...
随机推荐
- 九度OJ 1068:球的半径和体积 (基础题)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5385 解决:1949 题目描述: 输入球的中心点和球上某一点的坐标,计算球的半径和体积 输入: 球的中心点和球上某一点的坐标,以如下形式输 ...
- java常用的基础容器
1 Vector and ArrayList 它们都是可以随机访问的.它们的区别是Vector是线程安全的,而ArrayList不是线程安全的. 2 HashMap的底层实现机制 2.1 底层数据结构 ...
- mybatis 执行查询时报错 【Error querying database. Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: Cannot find class: 】
org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: java.sql.SQLE ...
- install_driver(mysql) failed
安装好了mysql监控神器innotop,正得意,innotoop不可用,其错误提示为install_driver(mysql) failed: Can't load '/usr/lib64/ ...
- 使用阿里云maven镜像加速jar包下载
编辑 MAVEN_HOME/conf 文件夹下的 settings.xml,找到 <mirrors> 节点,把下面内容添加在其子节点内: <mirror> <id> ...
- GDB调试core文件(2)
使用gdb和core dump迅速定位段错误 关键字:gdb.段错误.core dump 一.什么是core dump core:内存.核心的意思: dump:抛出,扔出: core dump:前提: ...
- Spring Boot2.0之性能优化
1.JVM参数调优 针对运行效果 吞吐量 初始堆内存与最大堆尽量相同 减少垃圾回收次数 2.扫包优化: 启动优化 默认Tomcat容器改为Undertow Tomcat的吞吐量500 ...
- 纯CSS3实现淡入淡出下拉菜单
纯CSS3实现淡入淡出下拉菜单是一款比较简单清新的CSS3教程下拉菜单,这款下拉菜单是垂直方向的,点击主菜单项可以展开和折叠子菜单,在展开折叠的过程中伴随着淡入淡出的动画效果 源代码:http://w ...
- 分享知识-快乐自己:Struts2文件上传及文件下载
1)Struts2单文件上传 action:类文件 package com.mlq.action; import com.opensymphony.xwork2.ActionSupport; impo ...
- 初入 CLR - 阅读《CLR via C#》笔记
最近买了一本书<CLR via C#>阅读了第一章 - CLR 的执行模型,对 .NET 一直提到的 CLR 和 .NET Framework 有了一个大致的了解.我理解主要体现在: ■ ...