链接: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.

输入描述:

  1. The input starts with one line containing exactly one integer T which is the number of test cases. (1 T 20)
  2.  
  3. 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. , 1 M 10

18

  1. ,

  1. )

输出描述:

  1. 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.

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

-->

示例1

输入

复制

  1. 2
  2. 2 2
  3. 3 4

输出

复制

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

  1. 参考博客:
    AC代码:
  1. #include <map>
  2. #include <set>
  3. #include <stack>
  4. #include <cmath>
  5. #include <queue>
  6. #include <cstdio>
  7. #include <vector>
  8. #include <string>
  9. #include <bitset>
  10. #include <cstring>
  11. #include <iomanip>
  12. #include <iostream>
  13. #include <algorithm>
  14. #define ls (r<<1)
  15. #define rs (r<<1|1)
  16. #define debug(a) cout << #a << " " << a << endl
  17. using namespace std;
  18. typedef long long ll;
  19. const ll maxn = 1e6 + 10;
  20. const double eps = 1e-8;
  21. const ll mod = 998244353;
  22. const ll inf = 1e9;
  23. const double pi = acos(-1.0);
  24. ll inv[maxn];
  25. ll qow( ll a, ll b ) {
  26. ll ans = 1;
  27. while(b) {
  28. if(b&1) {
  29. ans = ans*a%mod;
  30. }
  31. a = a*a%mod;
  32. b /= 2;
  33. }
  34. return ans;
  35. }
  36. void init() { //求阶乘逆元
  37. inv[1] = 1;
  38. for( ll i = 2; i <= maxn-10; i ++ ) {
  39. inv[i] = (mod-mod/i)*inv[mod%i]%mod;
  40. }
  41. }
  42. int main() {
  43. ll T;
  44. scanf("%lld",&T);
  45. init();
  46. for( ll cas = 1, n, m; cas <= T; cas ++ ) {
  47. scanf("%lld%lld",&n,&m);
  48. ll A = m%mod, C = 1, ans = 0, M = min(n,m);
  49. n = n%mod, m = m%mod;
  50. for( ll i = 1; i <= M; i ++ ) {
  51. ans += A*C%mod;
  52. ans %= mod;
  53. A = (m-i)%mod*A%mod, C = (n-i)%mod*C%mod*inv[i]%mod;
  54. }
  55. printf("Case #%lld: %lld\n",cas,ans);
  56. }
  57. return 0;
  58. }

  

牛客多校第六场 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. MemCached的telnet命令行参数

    1.启动Memcache 常用参数 -p <num>      设置TCP端口号(默认不设置为: 11211) -U <num>      UDP监听端口(默认: 11211, ...

  2. 读JDK源码集合部分

    以前读过一遍JDK源码的集合部分,读完了一段时间后忘了,直到有一次面试简历上还写着读过JDK集合部分的源码,但面试官让我说说,感觉记得不是很清楚了,回答的也模模糊糊的,哎,老了记性越来越差了,所以再回 ...

  3. go 学习之路(三)

    一.strings和strconv使用 1.strings.HasPrefix(s string,prefix string) bool :判断字符串s是否以prefix开头 2.stings.Has ...

  4. Hadoop 系列(一)—— 分布式文件系统 HDFS

    一.介绍 HDFS (Hadoop Distributed File System)是 Hadoop 下的分布式文件系统,具有高容错.高吞吐量等特性,可以部署在低成本的硬件上. 二.HDFS 设计原理 ...

  5. webupload项目中使用

    目前项目需要一个多图上传的功能,使用LayUI并也是可以实现多图上传的,但是没有图片删除功能,参考了一下网上多图上传的插件,选择了WebUpload进行功能开发. 然而不幸的是,官方的插件并不带UI界 ...

  6. 学习TensorFlow的第一天

    https://www.cnblogs.com/wangxiaocvpr/p/5902086.html

  7. Java学习多线程第二天

    内容介绍 线程安全 线程同步 死锁 Lock锁 等待唤醒机制 1    多线程 1.1     线程安全 如果有多个线程在同时运行,而这些线程可能会同时运行这段代码.程序每次运行结果和单线程运行的结果 ...

  8. Django:在OS X环境下连接MySQL数据库

    正常的安装只需要执行以下2条命令: $ brew install mysql-connector-c $ pip3 install mysqlclient 但在执行 pip3 install mysq ...

  9. java多线程中wait/notify/sleep/join/yield方法以及多线程的六种状态

    刚开始学线程的时候也是被这几个方法搞的云里雾里的,尤其是一开始看的毕老师的视频,老师一直在强调执行权和执行资格,看的有点懵逼,当然不是说毕老师讲的不好,就是自己有点没听明白,后来复习看了一些其他的博客 ...

  10. Python.append()与Python.extend()的区别

    lst=[1,2] >>>[1,2] lst.append([3,4]) >>>[1, 2, [3, 4]] lst.extend([3,4]) >>& ...