zoukankan      html  css  js  c++  java
  • 2018山东省ACM省赛G题-Game

    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 ",ans);
    }
    return 0;
    }

     
  • 相关阅读:
    沙盒解决方案与场解决方案之间的差异
    Windows 7:77 个 Windows 7 提示
    SharePoint disable loopback check
    SharePoint 2010 工作流解决方案:序言
    SharePoint 2010 查看“运行时错误”
    sharepoint 链接库链接在新窗口打开
    如何启用SharePoint 2010的代码块
    沙盒解决方案注意事项
    ie8.0 不能用document.all兼容IE7模式
    php导出数据到excel,防止身份证等数字字符格式变成科学计数的方法
  • 原文地址:https://www.cnblogs.com/lglh/p/9028572.html
Copyright © 2011-2022 走看看