山东省第九届省赛G题game

题目是一个很像NIM博弈的一道dp问题,实际上就是利用了NIM博弈的结论,XOR为0

原题目的意思是给定n堆石头,可以取走0-d堆石头,问取走之后后手必胜(实际上就是xor为0的情况)的取法数目

就是利用dp,状态表示就是前i堆,取走j堆,xor值为k

初始化的的状态就是dp[i,0,0]=1;

转移方程为dp[i,j,k]=dp[i-1,j,k]+dp[i-1,j-1,k^val[i]];

也就是由第i堆不取产生k的情况,和第i堆取走之后前i-1堆k^val[i]的值

计算所有堆的抑或值,这样取出来的堆只需要值为sum就相当于取走直接剩下的抑或值为0

最后只需要计算dp[n][i][sum]的值,i∈[0,d],其中i=0的情况等价于sum=0的情况,直接处理

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4
 5 const int MOD=(int)1e9+7;
 6
 7 int dp[1001][12][1030];
 8 int num[1005];
 9
10 int main(){
11     int T;
12     std::cin>>T;
13     while(T--)
14     {
15         memset(dp,0,sizeof(dp));
16         int n,d;
17         scanf("%d%d",&n,&d);
18         int sum=0;
19         for(int i=1;i<=n;i++)
20         {
21             scanf("%d",&num[i]);
22             sum^=num[i];
23         }
24
25         for(int i=0;i<=n;i++)
26         {
27             dp[i][0][0]=1;
28         }
29
30         for(int i=1;i<=n;i++)
31         {
32             for(int j=1;j<=d;j++)
33             {
34                 for(int k=0;k<=1023;k++)
35                 {
36                     dp[i][j][k]=(dp[i-1][j][k]+dp[i-1][j-1][k^num[i]])%MOD;
37                 }
38             }
39         }
40
41         int ans=0;
42         for(int i=1;i<=d;i++)
43         {
44             ans=(ans+dp[n][i][sum])%MOD;
45         }
46         if(sum==0) ans++;
47
48         printf("%d\n",ans);
49
50     }
51     return 0;
52 }

原文地址:https://www.cnblogs.com/rign/p/10661066.html

时间: 2024-08-29 19:08:27

山东省第九届省赛G题game的相关文章

(山东省第一届省赛 I 题) SDUTOJ 2159 Ivan comes again! (线段树+set)

题目地址:SDUT 2159 这题的数据很水..几乎所有人都是水过去的..网上也没找到正解,全是水过去的.于是我来第一发正解23333. 首先,可以想到的是先离线下来,然后对行离散化,然后对于每行的所有列用set去存,那么怎么去找最小的行有大于给出列的列数呢?这时候线段树就可以登场了,用线段树来维护每一行的出现的最大列,这样就可以用线段树去搜了.然后删除添加操作同时在set与线段树中完成. 代码如下: #include <iostream> #include <string.h>

Sdut 2165 Crack Mathmen(数论)(山东省ACM第二届省赛E 题)

Crack Mathmen TimeLimit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描写叙述 Since mathmen take security very seriously, theycommunicate in encrypted messages. They cipher their texts in this way: for everycharacther c in the message, they replace c wit

第九届省赛-表达式求值(模拟)

表达式求值 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述 假设表达式定义为: 1. 一个十进制的正整数 X 是一个表达式. 2. 如果 X 和 Y 是 表达式,则 X+Y, X*Y 也是表达式; *优先级高于+. 3. 如果 X 和 Y 是 表达式,则 函数 Smax(X,Y)也是表达式,其值为:先分别求出 X ,Y 值的各位数字之和,再从中选最大数. 4.如果 X 是 表达式,则 (X)也是表达式. 例如: 表达式 12*(2+3)+Smax(333,220+2

Sdut 2108 Alice and Bob(数学题)(山东省ACM第四届省赛D题)

题目地址:sdut 2608 Alice and Bob Alice and Bob Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Alice and Bob like playing games very much.Today, they introduce a new game. There is a polynomial like this: (a0*x^(2^0)+1) * (a1 * x^(2^1)+1)*....

sdut 2603 Rescue The Princess(算是解析几何吧)(山东省第四届ACM省赛A题)

题目地址:sdut 2603 Rescue The Princess Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Several days ago, a beast caught a beautiful princess and the princess was put in prison. To rescue the princess, a prince who wanted to marry the princess

Sdut 2416 Fruit Ninja II(山东省第三届ACM省赛 J 题)(解析几何)

Time Limit: 5000MS Memory limit: 65536K 题目描写叙述 Haveyou ever played a popular game named "Fruit Ninja"? Fruit Ninja (known as Fruit Ninja HD on the iPad and Fruit Ninja THD for NvidiaTegra 2 based Android devices) is a video game developed by Hal

nyoj1273 河南省第九届省赛_&quot;宣传墙&quot;、状压DP+矩阵幂加速

宣传墙 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 ALPHA 小镇风景美丽,道路整齐,干净,到此旅游的游客特别多.CBA 镇长准备在一条道路南 面 4*N 的墙上做一系列的宣传.为了统一规划,CBA 镇长要求每个宣传栏只能占相邻的两个方格 位置.但这条道路被另一条道路分割成左右两段.CBA 镇长想知道,若每个位置都贴上宣传栏, 左右两段各有有多少种不同的张贴方案. 例如: N=6,M=3, K=2, 左,右边各有 5 种不同的张贴方案 输入 第一行: T 表示

山东省第六届省赛 H题:Square Number

Description In mathematics, a square number is an integer that is the square of an integer. In other words, it is the product of some integer with itself. For example, 9 is a square number, since it can be written as 3 * 3. Given an array of distinct

HDU 5003 Osu!(鞍山网络赛G题)

HDU 5003 Osu! 题目链接 就一签到题,排序之后for一遍计算出答案即可 代码: #include <cstdio> #include <cstring> #include <iostream> #include <string> #include <vector> #include <set> #include <map> #include <algorithm> #include <cmat