Generation I

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 ≤ 1018, 1 ≤ M ≤ 1018, )

输出描述:

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

题意:有n个集合,n次操作,第i次操作中可以选一个数(数的范围是1~m),向i~n集合中都加入这个数,问最后有多少种不同的结果。
显然这题是因为集合不能有相同数的性质才导致答案不是m^n。
考虑全部的集合总共用了多少种不同的数,设共用了k种不同的数,则第一个集合有k种放法,由于每种操作对⼀个后缀有影响,区分⽅方案只要考虑第⼀个被影响的位置即可。
所以考虑剩下的n-1个集合的情况,则需要在其中选择k-1个集合放新的不同的数。最后就是不同的数的放入顺序不同也会导致答案不同,因此还要对k-1个数求一下排序数。
化简前的公式:
化简后的公式:
 
但是这题还一个比较坑的地方是n,m,mod都很大,lucas用不了,不能直接求组合数。
于是按照公式中的枚举变量k一步一步的来,先算k=1的情况,然后k=x的情况都可以由k=x-1的情况递推而来。
#include <iostream>
#define N 1000005
using namespace std;
const long long mod=;
long long ny[N+];
long long f(long long a,long long b)
{
long long ans=;
while(b>)
{
if(b%==)ans=(ans*a)%mod; b/=;
a=(a*a)%mod;
}
return ans;
} int main()
{
int t,tot=;
scanf("%d",&t);
for(int i=;i<=N;i++)ny[i]=f(i,mod-); while(t--)
{
long long n,m,ans,upper,last;
scanf("%lld %lld",&n,&m); upper=min(n,m);
ans=last=m%mod; for(int i=;i<=upper;i++)
{
last*=(m+-i)%mod;
last%=mod;
last*=ny[i-];
last%=mod;
last*=(n+-i)%mod;
last%=mod;
ans+=last;
ans%=mod;
} printf("Case #%d: %lld\n",++tot,ans);
}
return ;
}

Generation I的更多相关文章

  1. 论文阅读(Zhuoyao Zhong——【aixiv2016】DeepText A Unified Framework for Text Proposal Generation and Text Detection in Natural Images)

    Zhuoyao Zhong--[aixiv2016]DeepText A Unified Framework for Text Proposal Generation and Text Detecti ...

  2. Task set generation

    Task set generation for uni- and multiprocessors: “Unifying Fixed- and Dynamic-Priority Scheduling b ...

  3. 使用-MM生成include指令和依赖生成(make include directive and dependency generation with -MM)

    I want a build rule to be triggered by an include directive if the target of the include is out of d ...

  4. PHPNG (next generation)

    PHPNG (next generation) This page gives short information about development state of a new PHP branc ...

  5. test generation和MBIST

    The problem of test generation Random test generation Deterministic algorithm for test generation fo ...

  6. 关于conversation generation的论文笔记

    对话模型此前的研究大致有三个方向:基于规则.基于信息检索.基于机器翻译.基于规则的对话系统,顾名思义,依赖于人们周密设计的规则,对话内容限制在特定领域下,实际应用如智能客服,智能场馆预定系统.基于信息 ...

  7. 1094. The Largest Generation (25)

    A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level bel ...

  8. Case Study: Random Number Generation(翻译教材)

    很荣幸,经过三天的努力.终于把自己翻译的教材做完了,现在把它贴出来,希望能指出其中的不足.   Case Study: Random Number Generation Fig. 6.7  C++ 标 ...

  9. Index Generation

    Index Generation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 230   Accepted: 89 Des ...

  10. PowerDesigner15(16)在生成SQL时报错Generation aborted due to errors detected during the verification of the mod

    1.用PowerDesigner15建模,在Database—>Generate Database (或者用Ctrl+G快捷键)来生产sql语句,却提示“Generation aborted d ...

随机推荐

  1. COGS 696. [IOI1996][USACO 2.3] 最长前缀

    ★   输入文件:prefix.in   输出文件:prefix.out   简单对比时间限制:1 s   内存限制:128 MB 描述 USACO 2.3.1 IOI96 在生物学中,一些生物的结构 ...

  2. (六)maven之本地仓库

     本地仓库 ①    运行机制: 当用户在pom.xml文件中添加依赖jar包时,maven会先从本地仓库查找,如果这个jar包在本地仓库中找不到,就从中央仓库下载到本地仓库,中央仓库是maven默认 ...

  3. scanf("%s",s)与gets(s)

    #include <stdio.h> void fun(char s[]) {; while(s[i]!='\0') {i++;} printf("%d",i);} v ...

  4. vue 数组更新 this.$set(this.dataList, data.index, data.data)

    vue 数组更新 this.$set(this.dataList, data.index, data.data) https://www.cnblogs.com/huangenai/p/9836811 ...

  5. Windows server 2012安装oracle11g(32/64位)步骤

    Oracle官方下地址: http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html以下两网址 ...

  6. false - (失败的)什么都不做

    总览 (SYNOPSIS) false [忽略命令行参数] false OPTION 描述 (DESCRIPTION) 程序 结束 时, 产生 表示 失败 的 状态码. 下列的 选项 没有 简写 形式 ...

  7. Java创建图片文件缩略图

    public static void uploadImg(InputStream file, String filePath, String fileName, int widthdist, int ...

  8. Linux关于FTP安全

    https://www.cnblogs.com/Hyber/archive/2017/02/04/6362916.htmlhttps://www.cnblogs.com/ichunqiu/p/7300 ...

  9. css去除链接 input 虚框

    /* css去掉虚框 */ :focus{-webkit-outline-style:none;-moz-outline-style:none;-ms-outline-style:none;-o-ou ...

  10. OJ 大整数减法

    描述 求两个大的正整数相减的差. 输入 共2行,第1行是被减数a,第2行是减数b(a > b).每个大整数不超过200位,不会有多余的前导零. 输出 一行,即所求的差. 样例输入 9999999 ...