zoukankan      html  css  js  c++  java
  • 2018 山东省省赛 G: Games

    题目描述

    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[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]。
    暴力转移就行了。
    #include <iostream>
    #include <bits/stdc++.h>
    #define maxn 1005
    using namespace std;
    typedef long long ll;
    const ll mod=1e9+7;
    int dp[maxn][12][2*maxn]={0};//前i个选j个,异或为k。
    //dp[i][j][k]=dp[i-1][j][k]+dp[i-1][j-1][k^a[i]];
    int main()
    {
        ll n,t,d,i,j,k;
        scanf("%lld",&t);
        ll a[maxn]={0};
        while(t--)
        {
            scanf("%lld%lld",&n,&d);
            memset(dp,0,sizeof(dp));
            ll maxim=-1;
            for(i=1;i<=n;i++)
            {
                scanf("%d",&a[i]);
                maxim=max(maxim,a[i]);
            }
            ll sum=a[1];
            for(i=2;i<=n;i++)
            {
                sum=sum^a[i];
            }
            for(i=1;i<=n;i++)
            {
                dp[i][0][0]=1;
            }
           for(i=1;i<=n;i++)
           {
               for(j=1;j<=d&&j<=i;j++)
               {
                   for(k=0;k<=2*maxim;k++)
                   {    if(i==1) dp[i][j][a[i]]=1;
                       else dp[i][j][k]=(dp[i-1][j][k]+dp[i-1][j-1][k^a[i]])%mod;
                   }
               }
           }
           ll ans=0;
           for(i=0;i<=d;i++)
           {
               ans=(ans+dp[n][i][sum])%mod;
           }
           printf("%lld
    ",ans);
        }
        return 0;
    }
    

      

  • 相关阅读:
    进击Node.js基础(一)
    关于bootstrap两个模态框的问题
    系列博文-Three.js入门指南(张雯莉)-网格 setInterval方法 requestAnimationFrame方法 使用stat.js记录FPS
    系列博文-Three.js入门指南(张雯莉)-照相机
    系列博文-Three.js入门指南(张雯莉)-静态demo和three.js功能概览
    for循环执行效率
    c/c++多维数组动态分配与释放
    C/C++数组指针与指针数组详解
    C/C++语言参数传递----值传递、引用传递、指针传递、指针引用传递
    float类型最大值和最小值
  • 原文地址:https://www.cnblogs.com/zyf3855923/p/9039982.html
Copyright © 2011-2022 走看看