https://codeforces.com/contest/1139/problem/D 题意 每次从1,m中选一个数加入队列,假如队列的gcd==1停止,问队列长度的期望 题解 概率正着推,期望反着推 发现每加入一个数,gcd会变为原来gcd的因数 \(dp[x]\) - > \(dp[gcd(x,i)]\) 但是方程却是反方向的 图片 代码 #include<bits/stdc++.h> #define MOD 1000000007 #define MAXN 100005 #def…
layout: post title: Codeforces Round 548 (Div. 2) author: "luowentaoaa" catalog: true tags: mathjax: true - codeforces https://codeforces.com/contest/1139/my D - Steps to One 思路…
题目链接: http://codeforces.com/contest/1139/problem/D 题意: 在$1$到$m$中选择一个数,加入到一个初始为空的序列中,当序列的$gcd$和为$1$时,停止加入,求序列的期望长度 数据范围: $1 \leq m \leq 10^{9}$ 分析: 定义$f[x$]为$gcd$等于$x$时把序列$gcd和$改变成1的期望长度,定义$G(x,y)$为$i$在1到$n$范围,满足$gcd(x,i)=y$,$i$的数量,得到以下公式: $$f[i]=1+\f…
https://codeforces.com/contest/1139/problem/C 题意 一颗有n个点的树,需要挑选出k个点组成序列(可重复),按照序列的顺序遍历树,假如经过黑色的边,那么这个序列就是好的,问有多少个好的序列 题解 黑边不连,红边连,假如两个点不在同一并查集,那么一定经过黑边 定义\(dp[i][j][k]\)为选择前i个点,起始点为j,是否已经经过黑边(k)的方案数 \(dp[i-1][j][0]*(n-N[fin(j)])+dp[i-1][j][1]*n - > dp…
题目链接: http://codeforces.com/problemset/problem/213/B B. Numbers time limit per test 2 secondsmemory limit per test 256 megabytes 问题描述 Furik loves writing all sorts of problems, especially such that he can't solve himself. You've got one of his proble…
题目链接: http://codeforces.com/problemset/problem/214/B Hometask time limit per test:2 secondsmemory limit per test:256 megabytes 问题描述 Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark fo…
D. Kindergarten Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/484/D Description In a kindergarten, the children are being divided into groups. The teacher put the children in a line and associated each child wi…
A. Boredom Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/455/problem/A Description Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and d…
题目链接:https://codeforces.com/contest/1105 C. Ayoub and Lost Array 题目大意:一个长度为n的数组,数组的元素都在[L,R]之间,并且数组全部元素的和可以被3整除,问有多少种方法构建出该数组.答案模1000000007 例 输入 2 1 3 输出 3 note:满足的情况只有[1,2],[2,1],[3,3] 解题思路:用dp[i][j]表示长度为i的数组,元素大小在[L,R]之间,并且元素和模3的余数为j的方案数,我们可以计算出[L,…
https://codeforces.com/contest/1113/problem/C 题意 一个n个数字的数组a[],求有多少对l,r满足\(sum[l,mid]=sum[mid+1,r]\),sum为异或和(n<=3e5,a[i]<=2^20) 题解 异或和为零的区间可以分成任意两个区间(这两个区间的异或和相等) 定义dp[i][j]为异或和为i,下标为j(只记录奇偶)的前缀个数 枚举r,然后累加l 代码 #include<bits/stdc++.h> #define M…