2018山东省ACM省赛 G题Games

时间限制: 2 Sec 内存限制: 128 MB

提交: 70 解决: 17

[提交][状态][讨论版][命题人:admin]

题目描述

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

这道题大概意思就是说要你取出一组数,使剩下的数的抑或和为0,找到有几种组合可以满足条件。由于最多不能取出超过10个,当然是要找取出的组合而非剩余的组合了,数据较大,不能暴力枚举。

虽然看起来挺像博弈论的,其实是三维DP,找组合的思路是前i个元素,取出j个,抑或和为k的取法数量有dp[i][k][j]个,先求出原组合的抑或和为x,扫一遍,求出∑dp[n][x][j],就是答案了,由于抑或运算不会超过最大值的二进制的最高位,所以每次扫到最高位即可,注意数组不要开小,虽然最大值是1000,但抑或运算可能达到1024-1,所以数组要开到1024以上。

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int A[1002][12][1030];
int B[1005];
int C[12];
const int M=1000000007;
int n,d,t,ans,m;
int finl;
int i,j,k,h;
int main()
{
    C[0]=1;
    for(i=1; i<=10; i++)
        C[i]=C[i-1]*2;
    scanf("%d",&t);
    while(t--)
    {
        ans=0;
        finl=0;
        m=0;
        memset(A,0,sizeof(A));
        scanf("%d%d",&n,&d);
        d=min(d,n);
        for(i=1; i<=n; i++)
        {
            scanf("%d",&B[i]);
            m=max(m,(int)B[i]);
            ans^=B[i];
            A[i][1][B[i]]=(A[i][1][B[i]]+1)%M;
        }
        for(i=0; i<=10; i++)
            if(C[i]>m)
            {
                m=C[i];
                break;
            }
        //cout<<m<<endl;
        for(i=1; i<=n; i++)
        {
            for(j=0; j<=m; j++)
            {
                for(k=1; k<=d; k++)
                {
                    A[i][k][j]%=M;
                    A[i-1][k][j]%=M;
                    A[i-1][k-1][B[i]^j]%=M;
                    A[i][k][j]=(A[i][k][j]+(A[i-1][k][j]+A[i-1][k-1][B[i]^j])%M)%M;
                }
            }
        }
        /*for(i=1;i<=d;i++)
        {
            for(j=0;j<m;j++)
            {
                for(k=1;k<=n;k++)
                    cout<<A[k][i][j]<<' ';
                cout<<endl;
            }
            cout<<endl;
        }*/
        if(ans==0) finl++;
        for(i=1; i<=d; i++)
        {
            finl=(finl+A[n][i][ans])%M;
        }
        printf("%d\n",finl);
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/shadowlink/p/9060450.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值