链接:

https://vjudge.net/problem/LightOJ-1318

题意:

In a country named "Ajob Desh", people play a game called "Ajob Game" (or strange game). This game is actually a game of words. The rules for the game are as follows:

It's an N player game and players are numbered from 1 to N. And the players alternate turns in a circular way. Player 1 starts first. The next turn is for player 2, then player 3 and so on. After the turn for the Nth player, player 1 gets his turn again and the same procedure is continued.

In each turn a player has to propose a pair of words. Each of the words should have length L, and the words should differ in exactly M positions. As their language has K alphabetical symbols, a word is a collection of symbols from these K alphabets.

The pair of words proposed by a player should differ in exactly M positions, it means that there should be exactly M positions where the two words have different symbols, and in other positions they have same symbols. For example, 'abc' and 'abd' differ in exactly 1 position, 'abc' and 'aca' differ in exactly 2 positions, 'abc' and 'cab' differ in exactly 3 positions.

In each turn a player has to propose a new pair of words. Two pairs are different if at least one word is different. Note that here pair refers to unordered pair. Let A, B, C be three different words, then (A, B) and (B, A) are same, but (A, C) and (A, B) are different. For example, if a player already proposed {abc, def}, then none can propose {abc, def} or {def, abc}. But a player can propose {abc, fed} or {abc, abc} or {pqc, abc} etc.

If a player fails to propose a new pair of words, he is treated as the loser of the game. And the game ends.

Let N = 2, K = 2, L = 2, M = 1 and the alphabet is {ab}. All the words of length 2 are: {aa, ab, ba, bb}. Player 1 chooses pair {aa, ab} (differs in 1 position as M = 1) then player 2 chooses pair {ab, bb}. After that player 1 chooses {aa, ba} then player 2 chooses {bb, ba}. And then there is no pair left for player 1, and so, player 1 will lose.

Now this game is played by N players who know this game very well thus they play optimally. You are given N, K, L and M; you have to find the loosing player.

思路:

一对字符串,一边是,\(k^l\)种,同时另一边需要有m个不同,则是\((k-1)^m\)

共有\(C_l^m*(k-1)^m*k^l\)

同时有重复,要除2,考虑2和n不一定互质,当k为偶数时用k/2,否则用(k-1)/2

代码:

// #include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string.h>
#include<set>
#include<queue>
#include<algorithm>
#include<math.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int MOD = 1e9+7;
const int MAXN = 1e6+10; LL n, k, l, m;
int pos;
int Pri[MAXN], Isp[MAXN], Cnt[MAXN]; void Init()
{
pos = 0;
for (int i = 2;i < MAXN;i++)
{
if (Isp[i] == 0)
Pri[++pos] = i;
for (int j = 1;j <= pos && 1LL*i*Pri[j] < MAXN;j++)
{
Isp[i*Pri[j]] = 1;
if (i%Pri[j] == 0)
break;
}
}
} void Upd(LL x, int sta)
{
for (int i = 1;i <= pos;i++)
{
LL tmp = x;
while(tmp)
{
Cnt[i] += sta*(tmp/Pri[i]);
tmp /= Pri[i];
}
}
} LL PowMod(LL a, LL b, LL p)
{
LL res = 1;
while(b)
{
if (b&1)
res = res*a%p;
a = a*a%p;
b >>= 1;
}
return res;
} LL C(LL n, LL m, LL p)
{
memset(Cnt, 0, sizeof(Cnt));
Upd(l, 1), Upd(m, -1), Upd(l-m, -1);
LL ans = 1;
for (int i = 1;i <= pos;i++)
ans = ans*PowMod(Pri[i], Cnt[i], p)%p;
return ans;
} int main()
{
// freopen("test.in", "r", stdin);
Init();
int t, cas = 0;
scanf("%d", &t);
while(t--)
{
printf("Case %d:", ++cas);
scanf("%lld%lld%lld%lld", &n, &k, &l, &m);
LL ans;
if (m != 0)
{
if (k&1)
ans = C(l, m, n)*PowMod(k, l, n)%n*PowMod(k-1, m-1, n)%n*(k/2)%n;
else
ans = C(l, m, n)*PowMod(k, l-1, n)%n*PowMod(k-1, m, n)%n*(k/2)%n;
}
else
ans = PowMod(k, l, n);
printf(" %lld\n", ans+1);
} return 0;
}

LightOJ - 1318 - Strange Game(组合数)的更多相关文章

  1. Light OJ 1318 Strange Game 组合数+高速幂+分解因子

    长度为l的用k种字符组成的字符串有k^l中 当中m个字符要不同样 那就是k^l*C(l, m)*(k-1)^m 有反复 要除以2 可是你mod n了 不能直接除 n不一定是素数 所以不能乘以逆元 所以 ...

  2. LightOJ - 1067 - Combinations(组合数)

    链接: https://vjudge.net/problem/LightOJ-1067 题意: Given n different objects, you want to take k of the ...

  3. LightOJ - 1246 Colorful Board(DP+组合数)

    http://lightoj.com/volume_showproblem.php?problem=1246 题意 有个(M+1)*(N+1)的棋盘,用k种颜色给它涂色,要求曼哈顿距离为奇数的格子之间 ...

  4. lightoj 1060 - nth Permutation(组合数+贪心)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1060 题解:如果是不重复数的这些操作可以用康托展开的逆来求,如果是有重复数字出 ...

  5. lightoj 1095 - Arrange the Numbers(dp+组合数)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1095 题解:其实是一道简单的组合数只要推导一下错排就行了.在这里就推导一下错排 ...

  6. lightoj 1226 - One Unit Machine(dp+大组合数去摸)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1226 题解:由于这些任务完成是有先后的所以最后一个完成的肯定是最后一个任务的子 ...

  7. lightoj 1134 - Be Efficient(组合数)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1134 题解:简单的一道组合题,现求一下前缀和,然后只要找前缀和膜m的结果相同的 ...

  8. LightOJ 1226 - One Unit Machine Lucas/组合数取模

    题意:按要求完成n个任务,每个任务必须进行a[i]次才算完成,且按要求,第i个任务必须在大于i任务完成之前完成,问有多少种完成顺序的组合.(n<=1000 a[i] <= 1e6 mod ...

  9. LightOJ - 1102 - Problem Makes Problem(组合数)

    链接: https://vjudge.net/problem/LightOJ-1102 题意: As I am fond of making easier problems, I discovered ...

随机推荐

  1. PHP调用webServer接口遇到的坑

    昨天公司分配给我一个任务,写一个中转接口,目标接口是一个webservice类型的接口,平时没有接触过,然后遇到一些坑, 一般情况下,能在浏览器打开并显示数据的接口是直接可以使用 CURL或者file ...

  2. golang学习笔记 ---常用第三方包

    包的介绍 包类似Java中概念,jar是源代码管理,分发的最小单位. 目前多数包来自 Github官方包来自 golang.org/x/... 可以在如下网址查询到高频使用的第三方包清单https:/ ...

  3. Unity - 绘制正五边形网格

    本文简述了Unity中绘制正五边形网格的基本方法:计算顶点信息.设置三角形覆盖信息.创建配置mesh 绘制方法 基本思路:计算出五边形顶点坐标信息作为数组,设置三角形包围方式,再创建新的mesh配置v ...

  4. Spring Boot 优雅的配置拦截器方式

    https://my.oschina.net/bianxin/blog/2876640 https://cs.xieyonghui.com/java/55.html 其实spring boot拦截器的 ...

  5. JavaScript字符串转数值

    JavaScript字符串转数值:方法主要有三种 转换函数.强制类型转换.利用js变量弱类型转换. 1. 转换函数 js提供了parseInt()和parseFloat()两个转换函数.前者把值转换成 ...

  6. 【开发工具】- Myeclipse10.7破解方法

    1.下载myeclipse 10,如果没有,可以使用链接:https://pan.baidu.com/s/1l9juqD4ALMuepVL6e5kgjA 密码:kpx6:当然时间久了可能链接失效,如有 ...

  7. 【Jmeter】他人总结篇链接(共八篇相关文章)

    [Jmeter]他人总结篇链接(共八篇相关文章) https://blog.csdn.net/mu_wind/article/category/9029006

  8. Audio Queue Services Programming Guide(音频队列服务编程指南)

    Audio Queue Services 的苹果官方文档: https://developer.apple.com/library/ios/documentation/MusicAudio/Conce ...

  9. PHP微信商户支付企业付款到零钱功能

    一 开通条件,就是首先要在微信平台设置好. 以下微信文档里有的,我这里大概掠几项比较重要的. 付款资金 企业付款到零钱资金使用商户号余额资金. 根据商户号的账户开通情况,实际出款账户有做区别: ◆ 默 ...

  10. 动态渲染左侧菜单栏 :menu tree 动态渲染

    其中后端代码不包含权限控制,同时支持二级(无子菜单) 和 三级菜单(无子菜单). 1.layui前端代码:(其他前端框架实现方法通用,不过需要修改js中append对应标签元素即可) <div ...