D1T1 煎蛋的疑惑excatalan

Input 1
2 1
Output 1
3
Input 2
9 3
Output 2
9996
Input 3
996 223
Output 3
361421692
Input 4
514223 0
Output 4
287888483



#include<bits/stdc++.h>
#define ll long long
using namespace std;const ll mod = 998244353;
const int N = 2e6+10;
ll M(ll a) {return a%mod;}
int n, m;
ll fac[N], inv[N];ll Pow(ll a, ll b) {ll c=1;while(b){if(b&1) c=M(c*a);b>>=1;a=M(a*a);}return c;}ll C(ll x, ll y) {if(x<y || x<0 || y<0) return 0;return M(M(fac[x]*inv[y])*inv[x-y]);
}ll Ca(ll a, ll b) {if(b<0) return 0;return M(C(a<<1, a) - C((a<<1), a-b-1) + mod);
}void work() {fac[0] = 1;for(int i = 1; i <= (n<<1); i++)fac[i] = M(fac[i-1]*i);inv[n<<1] = Pow(fac[n<<1], mod-2);for(int i = (n<<1); i; i--)inv[i-1] = M(inv[i]*i);
}int main() {scanf("%d%d", &n, &m);work();printf("%lld\n", M(Ca(n,m)-Ca(n,m-1)+mod));return 0;
}

D1T2 蘑菇shimeji

Input 1
5
1 2
1 3
2 4
2 5
Output 1
748683268
Input 2
10
1 2
2 3
1 4
2 5
4 6
6 7
3 8
3 9
4 10
Output 2
132579339
Input 3
514
每一条边都是i与i+1相连(0<i<514)
Output 2
831885280



#include<bits/stdc++.h>
#define ll long long
using namespace std;const ll mod = 998244353;
const int N = 1e6+5;
struct psx{int y, next;} e[N<<1];
int lin[N], len=0, n;
ll f[N];//该点所在连通块被选择
ll g[N];//该点所在连通块没有被选择ll M(ll a){return a%mod;}//取模
ll add(ll a, ll b) {return M(a+b);}//加法
ll Pow(ll a, ll b) {ll c=1;while(b){if(b&1) c=M(c*a); b>>=1; a=M(a*a);}return c;}//快速幂void insert(int xx, int yy) {e[++len].next = lin[xx];lin[xx] = len;e[len].y = yy;
}void dfs(int k, int fa) {f[k] = g[k] = 1;//本身for(int i = lin[k]; i; i = e[i].next) {int y = e[i].y;if(y == fa) continue;dfs(y, k);f[k] = add(f[k]*g[y],g[k]*f[y]);//k被选择,可以由选择y和选择k的其他儿子(或本身)两种情况传递g[k] = M(g[k]*g[y]);//k不被选择,那么儿子y必然不被选择}g[k] = add(g[k], f[k]); //如果k与fa[k]的边断了,相当于不选择k//如果没断,那么选择k就可以传递到选择fa[k]
}int main() {scanf("%d", &n);for(int i = 1; i < n; i++) {int u, v;scanf("%d%d", &u, &v);insert(u, v);insert(v, u);}dfs(1, 0);printf("%lld\n", M(f[1]*Pow((mod+1)/2,n-1)));//因为所求为期望,所以还需要乘2^(n-1)//(mod+1)/2为模mod意义下2的逆元return 0;
}


D1T3 墙wall

Input 1
3 514223
2 1 3
Output 1
4
Input 2
8 514223
1 5 6 3 4 8 7 2
Output 2
32
Input 3
223 514223
墙的排列为1~223
Output 3
223



#include<bits/stdc++.h>
#define ll long long
using namespace std;ll mod, ans=0, a, n;
ll f1[6005], f2[6005], p[6005];ll M(ll a) {return a%mod;}
void add(ll &a, ll b){a = M(a+b);}void solve() {for(int i = 1; i <= n; i++)for(int j = i-1; j >= 1; j--) if(p[i] < p[j]) add(f2[j], f1[i]);else add(f1[i], f2[j]);
}int main() {scanf("%lld%lld", &n, &mod);for(int i = 1; i <= n; i++) {scanf("%lld", &a);p[a] = i;} for(int i = 1; i <= n; i++)f1[i] = 1, f2[i] = 0;solve();for(int i = 1; i <= n; i++)add(ans, f1[i]);for(int i = 1; i <= n; i++)f1[i] = 0, f2[i] = 1;solve();for(int i = 1; i <= n; i++)add(ans, f2[i]);//由样例可知,单点有贡献,以上两种情况单点记录两次,要减去add(ans, mod-n);printf("%lld\n", M(ans+mod));return 0;
}

D2T1 a


Input 1
5
1
3
5
7
11
Output 1
2
554580199
522281449
849291288
19307947




#include<bits/stdc++.h>
#define ll long long
using namespace std;const int N = 1e7+10;
const ll mod = 998244353;
ll M(ll a) { return a%mod; }
int q;
ll f[N];快读dread()快输print()略ll Pow(ll a,ll b){ll c=1;while(b){if(b&1)c=M(c*a);b>>=1;a=M(a*a);}return c;}int main() {q = dread();ll ans=1;while( q-- ) {int n = dread();ll k = Pow(n, mod-2);f[n] = 1;for(int i = n-1; i>=0; i--)f[i] = M( M(f[i+1]*(n-i))*k+1 ); print(f[0]);}return 0;
}


D2T2 b


Input 1
1
9
1 2 2
2 3 2
3 4 6
3 8 4
2 5 5
5 6 2
2 7 6
1 9 3
4
2 5
3 8
1 7
1 10
Output 1
1
-1
2
3



D2T3 c


Input 1
3
2 3
4 5
6 7
Output 1
1
6
960





国庆集训1027-1028(未完成)相关推荐

  1. 牛客国庆集训派对Day6

    牛客国庆集训派对Day6 以下是我个人题解,出题人题解附带在最后 A.Birthday 费用流裸题,只要注意到1+3+5+...+2k−1=k21+3+5+...+2k-1 = k^21+3+5+.. ...

  2. 2019牛客国庆集训派对day2 K 2018(容斥)

    链接:https://ac.nowcoder.com/acm/contest/1107/K 来源:2019牛客国庆集训派对day2 题目描述   Given a, b, c, d, find out ...

  3. 2020牛客国庆集训派对day2 补题J

    2020牛客国庆集训派对day2 补题J:VIRUS OUTBREAK 题目描述 The State Veterinary Services Department recently reported ...

  4. 2020牛客国庆集训派对day3 I.Rooted Tree(哈代-拉马努金拆分数列)

    2020牛客国庆集训派对day3 I.Rooted Tree(哈代-拉马努金拆分数列) 题目 https://ac.nowcoder.com/acm/contest/7830/I 题意 给你n个点,问 ...

  5. 2020牛客国庆集训派对day2 H-STROOP EFFECT(英语题)

    2020牛客国庆集训派对day2 H-STROOP EFFECT(英语题) 题目 https://ac.nowcoder.com/acm/contest/7818/H 题意 这题目真的太难读懂了,赛后 ...

  6. 2020牛客国庆集训派对day8 G-Shuffle Cards(扩展STL容器,rope可持久化平衡树)

    2020牛客国庆集训派对day8 G-Shuffle Cards(扩展STL容器,rope可持久化平衡树) 题目 https://ac.nowcoder.com/acm/contest/7865/G ...

  7. 2016湖南湘潭邀请赛 - 2019牛客国庆集训派对day6

    2016湖南湘潭邀请赛 - 2019牛客国庆集训派对day6 A - 2016 题意:求一个2阶矩阵的n次幂,对7取模的结果 思路:可以用上面介绍的10进制倍增的方法.也可以用 n 对2016取模,还 ...

  8. 2020牛客国庆集训派对day1 A.ABB

    2020牛客国庆集训派对day1 A.ABB 题目链接 题目描述 Fernando was hired by the University of Waterloo to finish a develo ...

  9. 牛客国庆集训派对Day6 B.Board

    链接 [https://www.nowcoder.com/acm/contest/206/B] 分析 只要在n*n范围内随便找一个斜对角的一个格子去计算就知道了 具体看代码体会吧 代码 #includ ...

最新文章

  1. Yoshua Bengio团队通过在网络「隐藏空间」中使用降噪器以提高深度神经网络的「鲁棒性」...
  2. 那些顶级的AI机器人“大脑”
  3. std thread
  4. Python的可变类型与不可变类型
  5. 配置exchange 2010高可用群集服务(dag)
  6. java编译系统资源不足_Ant编译项目资源不足
  7. 1.5 编程基础之循环控制 05 最高的分数
  8. 【转】jsp+servlet和SSM分别是如何实现文件上传(示例)
  9. coroutine - yield from
  10. db2 空值转换函数_Excel一键转换百分比
  11. 微型计算机常常采用三种线结构,中北大学微机原理习题册终极版考试必备
  12. java循环while之等差数列均值_java基础_while 循环语句的定义及用法
  13. JDBC连接池DBUtils使用
  14. 输入框正则表达式大全
  15. 网络编程-UDP编程
  16. Telink BLE MESH开发|ble mesh开发教程《四》telink_sig_mesh休眠与唤醒
  17. mysql 1093_mysql ERROR 1093 (HY000)
  18. java将Word转换成PDF两种方法
  19. algorithm2e笔记,记录一下常规操作
  20. 单片机进阶---HLK-W801硬件开发之制作PCB

热门文章

  1. 网关,默认网关,自动网关,路由,网关与路由器的关系
  2. S2-MLP v2: Improved Spatial-Shift MLP Architecture for Vision
  3. UPS电源即插即用的USB接口板方案
  4. Linux>>CentOS 7镜像下载
  5. JabRef文献管理软件简明教程
  6. 过TP C读内存 测试可过dxf 切换CR3
  7. Freescale Bootloader detail for MC56F8037
  8. 深度学习入门基础CNN系列——卷积计算
  9. 非侵入式电荷负载分解NILM中的评价指标
  10. 安徽专科计算机专业哪个学校好,安徽排名前十的大专院校:安徽省最好的大专学校排名...