码迷,mamicode.com
首页 > 其他好文 > 详细

acm山东省赛 Games(dp取数)

时间:2018-07-19 19:09:58      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:rom   scribe   UNC   pil   ace   取数   return   tar   name   

Games

Time Limit: 1000 ms Memory Limit: 65536 KiB

Problem Description

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

Input

The first line contains an integer TT, representing the number of test cases.
For each test cases, the first line are two integers nn and dd, which are described above.
The second line are nn positive integers a_iai?, representing the number of stones in each pile.
T \leq 5, n \leq 10^3, d \leq 10, a_i \leq 10^3T5,n103,d10,ai?103

Output

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

Sample Input

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

Sample Output

2
5

Hint

 

Source

“浪潮杯”山东省第九届ACM大学生程序设计竞赛(感谢山东财经大学)
 
 
 
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define MAX 1005
#define MOD 1000000007
using namespace std;
typedef long long ll;
 
int a[MAX];
int dp[MAX][15][1025];
 
int main()
{
    int t,n,d,i,j,k;
    scanf("%d",&t);
    while(t--){
        scanf("%d%d",&n,&d);
        int sum=0;
        for(i=1;i<=n;i++){
            scanf("%d",&a[i]);
            sum^=a[i];
        }
        for(i=0;i<=n;i++){
            dp[i][0][0]=1;
        }
        for(i=1;i<=n;i++){
            for(j=1;j<=d;j++){
                for(k=0;k<1024;k++){
                    dp[i][j][k]=dp[i-1][j][k]+dp[i-1][j-1][k^a[i]];
                    dp[i][j][k]%=MOD;
                }
            }
        }
        ll ans=0;
        for(i=0;i<=d;i++){
            ans+=dp[n][i][sum];
            ans%=MOD;
        }
        printf("%lld\n",ans);
    }
    return 0;
}

 

acm山东省赛 Games(dp取数)

标签:rom   scribe   UNC   pil   ace   取数   return   tar   name   

原文地址:https://www.cnblogs.com/yzm10/p/9337487.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!