链接:https://www.nowcoder.com/acm/contest/144/C
来源:牛客网

Oak is given N empty and non-repeatable sets which are numbered from 1 to N.

Now Oak is going to do N operations. In the i-th operation, he will insert an integer x between 1 and M to every set indexed between i and N.

Oak wonders how many different results he can make after the N operations. Two results are different if and only if there exists a set in one result different from the set with the same index in another result.

Please help Oak calculate the answer. As the answer can be extremely large, output it modulo 998244353.

输入描述:

The input starts with one line containing exactly one integer T which is the number of test cases. (1 ≤ T ≤ 20)

Each test case contains one line with two integers N and M indicating the number of sets and the range of integers. (1 ≤ N ≤ 10

18

, 1 ≤ M ≤ 10

18

, 

)

输出描述:

For each test case, output "Case #x: y" in one line (without quotes), where x is the test case number (starting from 1) and y is the number of different results modulo 998244353.

输入例子:
2
2 2
3 4
输出例子:
Case #1: 4
Case #2: 52

-->

示例1

输入

复制

2
2 2
3 4

输出

复制

Case #1: 4
Case #2: 52 题意:有n个set(没有重复元素),有无限个1~m,第i次操作可以从中选一个元素往set i~n里面插入 
求有多少种可能结果(只要有一个set不是完全相同)
分析:

参考博客:
AC代码:
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define ls (r<<1)
#define rs (r<<1|1)
#define debug(a) cout << #a << " " << a << endl
using namespace std;
typedef long long ll;
const ll maxn = 1e6 + 10;
const double eps = 1e-8;
const ll mod = 998244353;
const ll inf = 1e9;
const double pi = acos(-1.0);
ll inv[maxn];
ll qow( ll a, ll b ) {
ll ans = 1;
while(b) {
if(b&1) {
ans = ans*a%mod;
}
a = a*a%mod;
b /= 2;
}
return ans;
}
void init() { //求阶乘逆元
inv[1] = 1;
for( ll i = 2; i <= maxn-10; i ++ ) {
inv[i] = (mod-mod/i)*inv[mod%i]%mod;
}
}
int main() {
ll T;
scanf("%lld",&T);
init();
for( ll cas = 1, n, m; cas <= T; cas ++ ) {
scanf("%lld%lld",&n,&m);
ll A = m%mod, C = 1, ans = 0, M = min(n,m);
n = n%mod, m = m%mod;
for( ll i = 1; i <= M; i ++ ) {
ans += A*C%mod;
ans %= mod;
A = (m-i)%mod*A%mod, C = (n-i)%mod*C%mod*inv[i]%mod;
}
printf("Case #%lld: %lld\n",cas,ans);
}
return 0;
}

  

牛客多校第六场 C Generation I 组合数学 阶乘逆元模板的更多相关文章

  1. 牛客多校第六场 J Heritage of skywalkert 随即互质概率 nth_element(求最大多少项模板)

    链接:https://www.nowcoder.com/acm/contest/144/J来源:牛客网 skywalkert, the new legend of Beihang University ...

  2. 牛客多校第六场-H-Pair

    链接:https://ac.nowcoder.com/acm/contest/887/H来源:牛客网 题目描述 Given three integers A, B, C. Count the numb ...

  3. 牛客多校第五场 E room 二分图匹配 KM算法模板

    链接:https://www.nowcoder.com/acm/contest/143/E来源:牛客网 Nowcoder University has 4n students and n dormit ...

  4. 同构图+思维构造——牛客多校第六场E

    考的其实是同构图的性质: 1.同构图的顶点数,边数相等 2.同构图通过点的映射后邻接矩阵相同 这篇博客讲的很好https://www.jianshu.com/p/c33b5d1b4cd9 本题还需要一 ...

  5. 2018牛客多校第六场 G.Pikachu

    题意: 给出一棵n个点的树,每条边有边权.对这个树加边变成一个完全图.新加的边的权值为边上两点在树上的距离.求完全图上任意两点的最大流之和. 题解: 一共有C(n,2)个点对.假设当前求s到t之间的最 ...

  6. 2018牛客多校第六场 I.Team Rocket

    题意: 给出n个区间和m个点(点按顺序给出且强制在线).每个区间只会被第一个他包含的点摧毁.问每个点能摧毁多少个区间以及每个区间是被哪个点摧毁的. 题解: 将n个区间按照左端点排序,然后用vector ...

  7. 牛客多校第六场C

    一个数很大,并不能预处理,所以要进行公式变换,存前一个的值就好 #include <bits/stdc++.h> using namespace std; typedef long lon ...

  8. Palindrome Mouse(2019年牛客多校第六场C题+回文树+树状数组)

    目录 题目链接 题意 思路 代码 题目链接 传送门 题意 问\(s\)串中所有本质不同的回文子串中有多少对回文子串满足\(a\)是\(b\)的子串. 思路 参考代码:传送门 本质不同的回文子串肯定是要 ...

  9. 2019牛客多校第六场 B - Shorten IPv6 Address 模拟

    B - Shorten IPv6 Address 题意 给你\(128\)位的二进制,转换为十六进制. 每\(4\)位十六进制分为\(1\)组,每两组用一个\(":"\)分开. 每 ...

随机推荐

  1. 在ABP中灵活使用AutoMapper

    demo地址:ABP.WindowsService 该文章是系列文章 基于.NetCore和ABP框架如何让Windows服务执行Quartz定时作业 的其中一篇. AutoMapper简介 Auto ...

  2. 北大ACM试题分类+部分解题报告链接

    转载请注明出处:優YoU http://blog.csdn.net/lyy289065406/article/details/6642573 部分解题报告添加新内容,除了原有的"大致题意&q ...

  3. 你了解HTTPS,但你可能不了解X.509

    世上根本就没有HTTPS协议,只有HTTP协议.——知乎某答友 某天,收到领导指示:学习一下X.509相关原理. 很多开发者可能和我一样觉得X.509这个词很陌生,但其实我们经常和它打交道,属于典型的 ...

  4. spring-boot项目的docker集成化部署(一)

    目录 spring-boot项目的docker集成化部署 前言 基本思路与方案 基本步骤 准备源码 服务器和基础环境 结语 1. 本文总结: 2. 后期优化: spring-boot项目的docker ...

  5. git bash 初始化配置

    这里只针对 windows 下,使用git 时的一些初始配置 1. git bash 安装 下载地址: https://git-for-windows.github.io/ 根据提示,一步步安装即可 ...

  6. C#实现简单爬虫

    分享之前写过的一个爬虫,采集数据,存入数据库的简单实现. github地址:https://github.com/CodesCreator/biu-biu-biu-

  7. 常量Const

    常量Const YEAR = 2019 # 全部大写的变量名为常量 注释 给不能理解的写一个描述 便于理解 增强可读性 三种形式 单行(当行)注释:# 只注释一行 不能换行 注释的代码不执行 不使用 ...

  8. Java——类型信息

    1.Class对象 Class对象是一个特殊的对象,它包含了与类有关的信息.Class对象就是用来创建类的所有常规对象的. 类是程序的一部分,每个类都有一个Class对象,每当编写并且编译一个新类,就 ...

  9. mybatis学习的终极宝典

    **********************************************************************************************一:myba ...

  10. 理解Go协程与并发

    协程 Go语言里创建一个协程很简单,使用go关键字就可以让一个普通方法协程化: package main import ( "fmt" "time" ) fun ...