博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Games
阅读量:5173 次
发布时间:2019-06-13

本文共 2863 字,大约阅读时间需要 9 分钟。

题目描述

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.

样例输入

25 21 1 2 3 46 31 2 4 7 1 2

样例输出

25 尼姆博弈:定理:(a1,a2,...,aN)为奇异局势当且仅当a1^a2^...^aN=0     比赛的时候只知道是博弈,让剩下的异或和为0 这个主要还是DP dp[i][j][k]=dp[i-1][j][k]+dp[i-1][j-1][k^a[i]]; 表示前i个,取j,异或为k。 则可由第i个不取,异或为k,第i个取,则 设x^a[i]=k ,x=k^a[i]。 取哪一个数就再异或就好了 暴力转移就好
1 #include 
2 #include
3 #define maxn 1005 4 using namespace std; 5 typedef long long ll; 6 const ll mod=1e9+7; 7 int dp[maxn][12][2*maxn]={
0};//前i个选j个,异或为k。 8 //dp[i][j][k]=dp[i-1][j][k]+dp[i-1][j-1][k^a[i]]; 9 int main()10 {11 ll n,t,d,i,j,k;12 scanf("%lld",&t);13 ll a[maxn]={
0};14 while(t--)15 {16 scanf("%lld%lld",&n,&d);17 memset(dp,0,sizeof(dp));18 ll maxim=-1;19 for(i=1;i<=n;i++)20 {21 scanf("%d",&a[i]);22 maxim=max(maxim,a[i]);23 }24 ll sum=a[1];25 for(i=2;i<=n;i++)26 {27 sum=sum^a[i];28 }29 for(i=1;i<=n;i++)30 {31 dp[i][0][0]=1;32 }33 for(i=1;i<=n;i++)34 {35 for(j=1;j<=d&&j<=i;j++)36 {37 for(k=0;k<=2*maxim;k++)38 { if(i==1) dp[i][j][a[i]]=1;39 else dp[i][j][k]=(dp[i-1][j][k]+dp[i-1][j-1][k^a[i]])%mod;40 }41 }42 }43 ll ans=0;44 for(i=0;i<=d;i++)45 {46 ans=(ans+dp[n][i][sum])%mod;47 }48 printf("%lld\n",ans);49 }50 return 0;51 }
View Code

dp还不怎么会 嘤

转载于:https://www.cnblogs.com/smallocean/p/9041227.html

你可能感兴趣的文章
TypeError: db.collection is not a function
查看>>
【Finish】Python Day 5
查看>>
并发容器 —— 总纲
查看>>
Java 第六周总结
查看>>
exit与_exit
查看>>
解决iOS应用内购买报错:invalidProductIdentifiers
查看>>
java模式之命令模式
查看>>
android游戏开发笔记(1)——画图及输入响应(一只被玩弄的老鼠)
查看>>
[ELK]快速搭建简单的日志分析平台
查看>>
2 除法啰嗦,不仅是python。
查看>>
Quick3.3 final 创建新项目,用VS编译总是过期的问题解决
查看>>
Unity C# 多态 委托 事件 匿名委托 Lambda表达式 观察者模式 .NET 框架中的委托和事件...
查看>>
数据结构化与保存
查看>>
plsql和tsql常用函数比对
查看>>
json 基础知识
查看>>
MySQL 的 CASE WHEN 语句
查看>>
mysql行锁深入研究
查看>>
getline函数的用法
查看>>
【转】.NET NPOI操作Excel常用函数
查看>>
贪心,布置作业
查看>>