题目链接:https://nanti.jisuanke.com/t/31000

题意:有N堆石子(N为大数),每堆的个数按一定方式生成,问先手取若干堆进行尼姆博弈,必胜的方式有多少种。

题解:因为 k < 4096,所以出现的数最多只有4096个,对每个数字只考虑出现奇/偶次进行dp,答案是所有不等于0的dp值的和。然后如果一个数字出现x次,它对自己出现奇数次的方案数和偶数次的方案数贡献都是乘上2 ^ (x - 1),每个数字的贡献都是2 ^ (x - 1) 总贡献就是2 ^ (N - ∑(vis[i]))。大数可以一边读入一边取模。

 #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mst(a,b) memset((a),(b),sizeof(a))
#define mp(a,b) make_pair(a,b)
#define fi first
#define se second
#define pi acos(-1)
#define pii pair<int,int>
const int INF = 0x3f3f3f3f;
const double eps = 1e-;
const int MAXN = 1e7 + ;
const int MAXM = 2e6 + ;
const ll mod = 1e9 + ; bool vis[];
int dp[][];
vector<int>vec;
int f[]; ll pow_mod(ll a, ll n) {
ll ans = ;
while(n) {
if(n & ) ans = ans * a % mod;
a = a * a % mod;
n >>= ;
}
return ans;
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
ll ans = ;
char ch;
int len = ;
int n = 1e9;
while() {
scanf("%c", &ch);
if(ch == ' ') break;
ans = pow_mod(ans, );
if(len == ) ans = ;
ans = ans * (1ll << (ch - '')) % mod;
if(len <= ) {
if(len == )
n = ;
n = n * + ch - '';
len++;
}
}
int x;
scanf("%d", &x);
int temp = x;
int a, b, c, d, e, k;
scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &k);
vec.push_back(x);
vis[x] = true;
for(int i = ; i <= ; i++) {
int x1 = 1ll * a * i * i % k * i * i % k;
int x2 = 1ll * b * i * i % k * i % k;
int x3 = 1ll * c * i * i % k;
int x4 = 1ll * d * i;
x = (x1 + x2 + x3 + x4 + e - ) % k + ;
f[i] = x;
}
int all = ;
while(all < n) {
all++;
int now = f[temp];
if(!vis[now]) {
vis[now] = true;
vec.push_back(now);
temp = now;
} else break;
}
int sz = vec.size();
dp[][] = ;
int pre = , now = ;
for(int i = ; i <= sz; i++) {
swap(pre, now);
int num = vec[i - ];
for(int j = ; j < ; j++) dp[now][j] = dp[pre][j];
for(int j = ; j < ; j++) {
dp[now][j ^ num] += dp[pre][j];
if(dp[now][j ^ num] >= mod) dp[now][j ^ num] -= mod;
}
}
ll sum = ;
for(int i = ; i < ; i++) {
sum += dp[now][i];
if(sum >= mod) sum -= mod;
}
ll inv = pow_mod(, sz);
inv = pow_mod(inv, mod - );
ans = ans * inv % mod;
ans = ans * sum % mod;
printf("%lld\n", ans);
return ;
}

ACM-ICPC 2018 南京赛区网络预赛 K. The Great Nim Game(博弈)的更多相关文章

  1. ACM-ICPC 2018 南京赛区网络预赛B

    题目链接:https://nanti.jisuanke.com/t/30991 Feeling hungry, a cute hamster decides to order some take-aw ...

  2. 计蒜客 30996.Lpl and Energy-saving Lamps-线段树(区间满足条件最靠左的值) (ACM-ICPC 2018 南京赛区网络预赛 G)

    G. Lpl and Energy-saving Lamps 42.07% 1000ms 65536K   During tea-drinking, princess, amongst other t ...

  3. 计蒜客 30990.An Olympian Math Problem-数学公式题 (ACM-ICPC 2018 南京赛区网络预赛 A)

    A. An Olympian Math Problem 54.28% 1000ms 65536K   Alice, a student of grade 66, is thinking about a ...

  4. ACM-ICPC 2018 南京赛区网络预赛 B. The writing on the wall

    题目链接:https://nanti.jisuanke.com/t/30991 2000ms 262144K   Feeling hungry, a cute hamster decides to o ...

  5. ACM-ICPC 2018 南京赛区网络预赛

    轻轻松松也能拿到区域赛名额,CCPC真的好难 An Olympian Math Problem 问答 只看题面 54.76% 1000ms 65536K   Alice, a student of g ...

  6. ACM-ICPC 2018 南京赛区网络预赛 L. Magical Girl Haze

    262144K   There are NN cities in the country, and MM directional roads from uu to v(1\le u, v\le n)v ...

  7. ACM-ICPC 2018 南京赛区网络预赛(12/12)

    ACM-ICPC 2018 南京赛区网络预赛 A. An Olympian Math Problem 计算\(\sum_{i=1}^{n-1}i\cdot i!(MOD\ n)\) \(\sum_{i ...

  8. ACM-ICPC 2018 南京赛区网络预赛 J.sum

    A square-free integer is an integer which is indivisible by any square number except 11. For example ...

  9. ACM-ICPC 2018 南京赛区网络预赛 E题

    ACM-ICPC 2018 南京赛区网络预赛 E题 题目链接: https://nanti.jisuanke.com/t/30994 Dlsj is competing in a contest wi ...

随机推荐

  1. (模板)poj2387(dijkstra+优先队列优化模板题)

    题目链接:https://vjudge.net/problem/POJ-2387 题意:给n个点(<=1000),m条边(<=2000),求结点n到结点1的最短路. 思路:dijkstra ...

  2. IDEA操作之FileHeager设置

    作用:头部注释添加,一般用于记录类的创建者等信息. 1. 打开配置 File->Settings->Editor->File and Code Templates->Inclu ...

  3. S02_CH09_UART串口中断实验

    S02_CH09_UART串口中断实验 本章的UART中断将在之前PL_PS中断和定时器中断上推导出来,因此本章有点难度,如果前两章还不是很熟悉的话,需要返回到前面两章把这两章的内容再次消化一下,再来 ...

  4. 禅道工具的下载和使用(原地址:https://www.cnblogs.com/ydnice/p/5800256.html)

    下载地址:http://sourceforge.net/projects/zentao/files/8.2/ZenTaoPMS.8.2.stable.exe/download 1.解压ZenTaoPM ...

  5. MySQL create table语法中的key与index的区别

    在create table的语句中,key和index混淆在一起,官方手册中的解释是这样: KEY is normally a synonym for INDEX. The key attribute ...

  6. Linux 创建用户 用户组 用户权限

    首先 你要有个root账号 然后才能做下面几条操作: useradd username 创建用户usernamepasswd user_pwd     给已创建的用户username设置密码 关于us ...

  7. VBA学习资料分享-1

    近年来,人工智能的概念深入人心,许多企业也正逐步或已推行办公自动化,寻求人力时间成本的降低,从而提升效益.对企业来说,要完全使用人工智能将工作流程自动化恐怕是没那么容易的,可以的话成本也不低,所以使用 ...

  8. [JZOJ3521]道路覆盖--状压DP

    题目链接 略略略 分析 首先一看到使得最低的高度最高就想到了二分,于是就转化成了一个是否可行的问题 发现这个\(k\)都很小,考虑使用状态压缩DP 但是我一开始发现似乎并不好设计状态...如果这个\( ...

  9. java中数组的定义

    1. 一维数组 int[] arr = new int[3];//需要一个容器,但是暂时不给具体的数值 int[] arr = new int[3]{1,2,3};//直接给定具体数值 int[] a ...

  10. VUE【一、概述】

    早上写的忘了保存..还有很多唠叨的内容...哎又得重新写一遍..想吐槽那个自动保存有卵用.. 今天周一,早上起来继续 由于周六加了一整天班,导致周日无心学习,一天都在玩游戏看电影,到了晚上反而更加空虚 ...