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

输入

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

 

输出

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

样例输入

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

样例输出

2
5
根据数据大小,显然用DP,此处个人觉得最重要的是深刻异或的性质,然后写递推式就比较简单了!
AC代码:

#include <bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int dp[1003][12][1040],a[1234];
int main()
{
int t,sum,ans,n,d;
scanf("%d",&t);
while(t--)
{
scanf("%d %d",&n,&d);
ans=0;
sum=0;
for(int i=1; i<=n; i++)
{
scanf("%d",&a[i]);
sum^=a[i];
}
dp[0][0][0]=1;
for(int i=1; i<=n; i++)
{
dp[i][0][0]=1;
for(int j=1; j<=d ; j++)
{
for(int k=0; k<=1204; k++)
{
dp[i][j][k]=dp[i-1][j][k]+dp[i-1][j-1][k^a[i]];
if(dp[i][j][k]>=mod)
{
dp[i][j][k]-=mod;
}
}
if(i==n)
{
ans+=dp[n][j][sum];
if(ans>=mod)
{
ans-=mod;
}
}
}
}
ans=(ans+dp[n][0][sum]);
printf("%d\n",ans);
}
return 0;
}

 

2018山东省ACM省赛G题-Game的更多相关文章

  1. 哈尔滨工程大学ACM预热赛 G题 A hard problem(数位dp)

    链接:https://ac.nowcoder.com/acm/contest/554/G Now we have a function f(x): int f ( int x ) {     if ( ...

  2. 第十届山东省acm省赛补题(1)

    今天第一场个人训练赛的题目有点恐怖啊,我看了半个小时多硬是一道都不会写.我干脆就直接补题去了.... 先补的都是简单题,难题等我这周末慢慢来吧... A Calandar Time Limit: 1 ...

  3. 第十届山东省acm省赛补题(2)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4124 L Median Time Limit: 1 Second      ...

  4. 福建工程学院第十四届ACM校赛G题题解

    外传:编剧说了不玩游戏不行 题意: 有n个石堆,我每次只能从某一堆中取偶数个石子,你取奇数个,我先手,先不能操作的人输.问最后谁能赢. 思路: 这个题仔细想想,就发现,取奇数的人有巨大的优势,因为假设 ...

  5. Sdut 2409 The Best Seat in ACM Contest(山东省第三届ACM省赛 H 题)(模拟)

    题目描述 Cainiao is a university student who loves ACM contest very much. It is a festival for him once ...

  6. 2018年第九届山东省ACM省赛总结

    去年打完区域赛之后,面对着两个队友都去找实习的情况,我自己对今年省赛还是有点慌的.不只一次的像我的队友说明自己很慌,但是老曹跟会长都说:“没事,慌啥!”前几场训练赛因为老曹跟秋洁有面试有时候只能一个人 ...

  7. 2018 ACM-ICPC徐州站网络赛 G题

    There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( xxx , yy ...

  8. 2013 acm 长沙网络赛 G题 素数+枚举 Goldbach

    题目 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3856 先预处理求出两个素数的和与积,然后枚举n-prime和n/pr ...

  9. Sdut 2416 Fruit Ninja II(山东省第三届ACM省赛 J 题)(解析几何)

    Time Limit: 5000MS Memory limit: 65536K 题目描述 Haveyou ever played a popular game named "Fruit Ni ...

随机推荐

  1. 【一天一道LeetCode】#60. Permutation Sequence.

    一天一道LeetCode系列 (一)题目 The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and ...

  2. 【一天一道LeetCode】#59. Spiral Matrix II

    一天一道LeetCode系列 (一)题目 Given an integer n, generate a square matrix filled with elements from 1 to n2 ...

  3. Mac下ImageMagick安装(libpng)

    猴子原创,欢迎转载.转载请注明: 转载自Cocos2Der-CSDN,谢谢! 原文地址: http://blog.csdn.net/cocos2der/article/details/42562705 ...

  4. Linux管理日记(二)

    14  启动内网端口转发 ### 2. 查看IP以及网卡信息 # 可以发现, eth0 的地址 inet addr:10.144.7.195, 此为内网网卡 # 公网网卡, eth1 的地址 inet ...

  5. 【一天一道LeetCode】#17. Letter Combinations of a Phone Number

    一天一道LeetCode (一)题目 Given a digit string, return all possible letter combinations that the number cou ...

  6. Android群英传笔记——第一章:Android体系与系统架构

    Android群英传笔记--第一章:Android体系与系统架构 图片都是摘抄自网络 今天确实挺忙的,不过把第一章的笔记做一下还是可以的,嘿嘿 1.1 Google的生态圈 还是得从Android的起 ...

  7. android JNI调用机制

    JNI的出现使得开发者既可以利用Java语言跨平台.类库丰 富.开发便捷等特点,又可以利用Native语言的高效. JNI是JVM实现中的一部分,因此Native语言和Java代码都运行在JVM的宿主 ...

  8. Windows7驱动调试小Tips

    v:* { } o:* { } w:* { } .shape { }p.MsoNormal,li.MsoNormal,div.MsoNormal { margin: 0cm; margin-botto ...

  9. 【50】java 匿名内部类剖析

    匿名内部类介绍: 匿名内部类也就是没有名字的内部类 正因为没有名字,所以匿名内部类只能使用一次,它通常用来简化代码编写 但使用匿名内部类还有个前提条件:必须继承一个父类或实现一个接口 匿名内部类的声明 ...

  10. 使用代码刷QQ的跨年红包

    使用的库从这里找: https://github.com/GameTerminator/dont-touch-white 关键代码就是一个while循环加上drag. import com.andro ...