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. django 第一次运行出错

    直接运行整个项目正常,直接运行url文件报错 报错内容: E:\Python\python.exe D:/Python储存文件/ceshiweb/ceshiweb/urls.pyTraceback ( ...

  2. [已解决]gitee初次使用git clone报错

    本文描述的错误按实际出现先后顺序排列,并且附上一些其他可能会出现的问题 错误1: JZKJ@DESKTOP-I7Q9QJ4 MINGW64 ~ $ git clone https://gitee.co ...

  3. Delphi与JAVA互加解密AES算法

    搞了半天终于把这个对应的参数搞上了,话不多说,先干上代码: package com.bss.util; import java.io.UnsupportedEncodingException; imp ...

  4. Bootstrap历练实例:表单控件状态(焦点)

    输入框焦点 当输入框 input 接收到 :focus 时,输入框的轮廓会被移除,同时应用 box-shadow. <!DOCTYPE html><html><head& ...

  5. 在Xcode中编辑运行 Python 脚本

    http://www.zhihu.com/question/19872198 打开Xcode,File->New->Project选中OS X下的Other点击External Build ...

  6. classList属性和className的区别

    className的不方便之处: 在操作类名时,需要通过className属性添加,删除和替换类名.因为className中是一个字符串,所以即使只修改字符串一部分,也必须每次都设置整个字符串的值.( ...

  7. Java语言的特点和特性

    1. Java语言的主要特点: 1. 跨平台性 所谓的跨平台性,是指软件可以不受计算机硬件和操作系统的约束而在任意计算机环境下正常运行.这是软件发展的趋势和编程人员追求的目标.之所以这样说,是因为计算 ...

  8. modprode

    modprobe命令 1.modprobe 命令是根据depmod -a的输出/lib/modules/version/modules.dep来加载全部的所需要模块. 2.删除模块的命令是:modpr ...

  9. 使用Lucene的api将索引创建到索引库中

    import org.apache.commons.io.FileUtils; import org.apache.lucene.document.Document; import org.apach ...

  10. 【js】--常用DOM库工具

    /* 2014年3月16号 常用DOM工具库*/var DOM={}; DOM.getElesByClass=function (strClassName,context){ if(typeof st ...