I.あなたの蛙が帰っています
 
 
 
这个题有点意思,是卡特兰数,自行百度就可以。卡特兰数用处很多,买票问题,出栈问题,括号配对等。传送门:很厉害
这个题就是出栈问题,问你出栈的方式有多少种。因为第一个不能最先输出来,随便写写就好了。
找出来公式就是C(2n,n)-C(2n,n-1)。对于这个题来说就是(C(2n,n)-C(2n,n-1)) - (C(2m,m)-C(2m,m-1))。
组合数就用到阶乘了(想一下平时手算的步骤),阶乘逆元快速幂,哗哗哗乱写就可以了。
 
代码:
 1 //I-卡特兰数-组合数学-阶乘逆元快速幂
2 #include<iostream>
3 #include<cstring>
4 #include<cstdio>
5 #include<cmath>
6 #include<cstdlib>
7 #include<algorithm>
8 #include<queue>
9 #include<vector>
10 using namespace std;
11 typedef long long ll;
12 const int maxn=2*1e5+10;
13 const int mod=998244353;
14 ll f[maxn];
15 void ff(){
16 f[0]=1;
17 for(int i=1;i<maxn;i++)
18 f[i]=(i*f[i-1])%mod;
19 }
20 ll poww(ll n,ll m){ //快速幂
21 ll ans=1;
22 while(m){
23 if(m&1)ans=(ans*n)%mod;
24 m=m>>1;
25 n=(n*n)%mod;
26 }
27 return ans;
28 }
29 ll cc(ll n,ll m){ //组合数
30 ll ans=f[n];
31 ans=(ans*poww(f[m],mod-2))%mod;
32 ans=(ans*poww(f[n-m],mod-2))%mod;
33 return ans;
34 }
35 int main(){
36 int t,n,m,h=0;
37 ff();
38 cin>>t;
39 while(t--){
40 cin>>n;
41 m=n-1;
42 ll ans=(cc(2*n,n)-cc(2*n,n-1)-cc(2*m,m)+cc(2*m,m-1)+2*mod)%mod;
43 cout<<"Case #"<<++h<<": "<<ans<<endl;
44 }
45 }

最新文章

  1. ecstore小记
  2. Basic knowledge of html (keep for myself)
  3. Android 高级UI设计笔记17:Android在非UI线程中显示Toast
  4. js 获取 input file 文件 附给 image src
  5. 感动前行——给医学媳妇写的演讲稿(非IT类)
  6. IE下支持文本框和密码框placeholder效果的JQuery插件
  7. 超级密码(bfs)
  8. RandomAccessFile实时读取大文件(转)
  9. Treblecross 博弈SG值
  10. jQuery 遍历 – 过滤
  11. 【翻译】使用Sencha Touch创建基于Tizen应用程序
  12. Q_UNUSED 的使用
  13. Python3-Cookbook总结 - 第二章:字符串和文本
  14. Sightseeing trip POJ - 1734 -Floyd 最小环
  15. tensorFlow可以运行的代码
  16. kettle中的合并记录使用记录
  17. F#周报2018年第51期
  18. 解决session只能被一个浏览器访问的问题
  19. 【JavaScript 6连载】五、继承的概念
  20. ES6模块化操作

热门文章

  1. Birthday Paradox
  2. 51nod_1154 回文串的划分
  3. input type=file输入框
  4. LOJ #6010. 「网络流 24 题」数字梯形
  5. mysql进阶三四五六
  6. 一篇文章看懂Facebook和新浪微博的智能FEED
  7. ios开发学习笔记002-运算符
  8. 爬虫:Scrapy1
  9. CSU 1809 Parenthesis(RMQ-ST+思考)
  10. hdu 3045 斜率优化DP