hdu4390-Number Sequence(容斥计算)】的更多相关文章

题意:给定b数列.计算有多少种数列 a1,a2,...,an 满足条件 a1*a2*...*an=b1*b2*-*bn (ai>1). 解法:处理出b数列中出现的全部质因子的数量记录在map中,然后进行容斥计算: 代码: /****************************************************** * author:xiefubao *******************************************************/ #pragma…
Y sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5297 Description Yellowstar likes integers so much that he listed all positive integers in ascending order,but he hates those numbers which can be written as a^b (a, b are positive integers,2…
传送门 题意 略 分析 是一道稍微变形的容斥题目,容斥一般的公式 \[ans=\sum_iAi-\sum_{i<j}{Ai∩Aj}+\sum_{i<j<k}{Ai∩Aj∩Ak}+...\] 但是这道题只要奇数次数的,那么对于第k项乘以一个系数\(2^{k-1}\) 具体见代码 trick 如果在每次dfs中for循环前加一个判断:if(lcm<=n)... 时间会从1000ms降到20ms 代码 #include<cstdio> #define ll long long…
至今觉得这场 edu 的 G 比 EF 都要简单-- 不知道为什么出题人要把 \(m=0\) 放进去,先特判掉. 要求至少一个 \(0\),至少一个 \(1\),至少一个 \(2\),容斥一波,变成总方案数-没有 \(0\)-没有 \(1\)-没有 \(2\)+没有 \(01\)+没有 \(02\)+没有 \(12\)+没有 \(012\). 没有 \(0\) 和没有 \(2\) 比较难搞,放到最后讨论. 没有 \(1\),考虑一个联通块,这个联通块所有数都一样,方案数是 \(2^{cnt}\)…
Co-prime Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5526    Accepted Submission(s): 2209 Problem Description Given a number N, you are asked to count the number of integers between A and B…
传送门 思路: 直接上点分治+容斥计算每个因数对应的贡献即可. 代码: #include<bits/stdc++.h> #define ri register int using namespace std; const int rlen=1<<18|1; inline char gc(){ static char buf[rlen],*ib,*ob; (ib==ob)&&(ob=(ib=buf)+fread(buf,1,rlen,stdin)); return i…
传送门 调了1h竟然是因为1004535809写成了998244353 "恰好有\(K\)种颜色出现了\(S\)次"的限制似乎并不容易达到,考虑容斥计算. 令\(c_j\)表示强制\(j\)种颜色恰好出现\(S\)次,其他颜色随意染的方案数.可以通过生成函数知道 \(\begin{align*} c_j &= \binom{m}{j} n! [x^n] (\frac{x^k}{k!})^j (\sum\limits_{i=0}^\infty \frac{x^i}{i!})^{m…
[BZOJ5287][HNOI2018]毒瘤(动态规划,容斥) 题面 BZOJ 洛谷 题解 考场上想到的暴力做法是容斥: 因为\(m-n\le 10\),所以最多会多出来\(11\)条非树边. 如果就是一棵树的话,显然答案就是独立集的个数. 非树边\(2^{11}\)枚举,强制非树边的两端同时备选导致不合法,容斥计算答案即可. 这样子的复杂度是\(O(2^{11}n)\),估算出来是\(2s\),然而在\(HNOI\)考场跑要\(20s\)(大雾 考虑如何优化这个东西. 我们\(2^{11}\)…
[BZOJ3129][SDOI2013]方程(容斥,拓展卢卡斯定理) 题面 BZOJ 洛谷 题解 因为答案是正整数,所先给每个位置都放一个就行了,然后\(A\)都要减一. 大于的限制和没有的区别不大,提前给他\(A_i\)个就好了. 假如没有小于的限制的话,那么就是经典的隔板法直接算答案. 如果提前给完之后,还剩\(M\)个球,要放进\(n\)个盒子,答案就是\(\displaystyle{M+n-1\choose n-1}\) 然而有一个小于的限制很烦人.发现数量很少,那么直接爆枚子集,强制一…
[BZOJ3294]放棋子(动态规划,容斥,组合数学) 题面 BZOJ 洛谷 题解 如果某一行某一列被某一种颜色给占了,那么在考虑其他行的时候可以直接把这些行和这些列给丢掉. 那么我们就可以写出一个\(dp\) 设\(f[i][r][c]\)表示考虑了前\(i\)种颜色,还剩下\(r\)行\(c\)列没被染色. 那么转移的时候枚举一下当前颜色染了\(a\)行\(b\)列转移就好了. 但是问题来了,怎么计算用\(K\)个棋子恰好覆盖\(a\)行\(b\)列的方案数呢? 恰好很不好算,那么我们换一下…
好题!学习了好多 写法①: 先求出gcd不为1的集合的数量,显然我们可以从大到小枚举计算每种gcd的方案(其实也是容斥),或者可以直接枚举gcd然后容斥(比如最大值是6就用2^cnt[2]-1+3^cnt[3]-1-(6^cnt[6]-1),cnt[x]表示x的倍数的个数),用容斥计算的话可以发现系数是莫比乌斯函数的相反数,就可以线性筛了.下面会记录一种O(MAX*ln(MAX))的筛法...求cnt的话可以选择直接枚举倍数计算O(MAX*ln(MAX))或者分解质因数,因为1e7内最多有8个不…
传送门 求第$k$个没有完全平方数因数的数 一开始是想筛一波莫比乌斯函数,然后发现时间复杂度要炸 于是老老实实看了题解 一个数的排名$k=x-\sum_{i=1}^{x}{(1-|\mu(i)|)}$ 因为$k$是不降的,所以我们可以考虑二分 那么如何计算区间$[1,x]$的无完全平方数因数的数的个数嘞? 我们可以考虑计算有平方因数的数的个数再减掉就可以了 那么这个可以用一个容斥计算,就是0个完全平方数因数的个数(即1的倍数)-1个完全平方数因数个数(即4,9,16...的倍数)+2个... 然…
[51nod1355]斐波那契的最小公倍数(min-max容斥) 题面 51nod 题解 显然直接算还是没法算的,所以继续考虑\(min-max\)容斥计算. \[lcm(S)=\prod_{T\subset S}gcd(T)^{(-1)^{|T|+1}}\] 而斐波那契数列满足\(gcd(f(a),f(b))=f(gcd(a,b))\), 于是和最小公倍佩尔数一样的类似处理 \[lcm(S)=\prod_{i=1}^{\infty}f(i)^{\sum_{T\subset S}[gcd(T)=…
传送门 为了方便我们设\(N\)是\(N,M,L\)中的最小值,某一个位置\((x,y,z)\)所控制的位置为集合\(\{(a,b,c) \mid a = x \text{或} b = y \text{或} c = z\}\) 发现恰好\(k\)个位置不大好算,考虑容斥计算强制\(k\)个位置是极大值的概率 对于极大值所在位置的数\(a_1,a_2,...,a_k\),假设\(a_1 > a_2 > ... > a_k\),那么我们还需要满足\(a_1 \geq a_1\)所在位置控制的…
Yellowstar likes integers so much that he listed all positive integers in ascending order,but he hates those numbers which can be written as a^b (a, b are positive integers,2<=b<=r),so he removed them all.Yellowstar calls the sequence that formed by…
Yada Number Problem Description: Every positive integer can be expressed by multiplication of prime integers. Duoxida says an integer is a yada number if the total amount of 2,3,5,7,11,13 in its prime factors is even. For instance, 18=2 * 3 * 3 is no…
Number Sequence Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 895 Accepted Submission(s): 374 Problem Description Given a number sequence b1,b2…bn.Please count how many number sequences a1,a2,..…
题意:https://codeforc.es/contest/1207/problem/D n个元素,每个元素有a.b两个属性,问你n个元素的a序列和b序列有多少种排序方法使他们不同时非递减(不同时good). 思路: 真难则反+容斥,反向考虑,ans1=如果a序列非递减则有a中各个数字出现次数的阶乘的乘积个,ans2=b序列也是一样. ans3=然后还要减去a序列和b序列都是good的方案数,就是元素相同的出现次数阶乘的乘积(注意,如果不存在双good就不算ans3). ANS就是:全排列 -…
ARC115 E AtCoder Problem Statement Given is a sequence of \(N\) integers \(A_1\),\(A_2\),...,\(A_N\). Print the number, modulo \(998244353\), of sequence of \(N\) integers \(X_1\),\(X_2\),...,\(X_N\) satisfying all of the following conditions: \(1 \l…
A Simple Chess 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5794 Description There is a n×m board, a chess want to go to the position (n,m) from the position (1,1). The chess is able to go to position (x2,y2) from the position (x1,y1), only and if…
B. Pasha and Phone Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/595/problem/B Description Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of ex…
Frogs Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5514 Description There are m stones lying on a circle, and n frogs are jumping over them.The stones are numbered from 0 to m−1 and the frogs are numbered fro…
转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Iahub and Permutations Iahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permutations. Iahubina is angry that she is no more import…
2015 asia xian regional F Color (容斥 + 组合数学) 题目链接http://codeforces.com/gym/100548/attachments Description Recently, Mr. Bigrecieved n flowers from his fans. He wants to recolor those flowerswith m colors. The flowers are put in a line. It is not allow…
Frogs Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1315    Accepted Submission(s): 443 Problem Description There are m stones lying on a circle, and n frogs are jumping over them.The stones a…
Permutation p is an ordered set of integers p1,  p2,  ...,  pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation…
B. Pasha and Phone time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consis…
题目链接 Problem Description Galen Marek, codenamed Starkiller, was a male Human apprentice of the Sith Lord Darth Vader. A powerful Force-user who lived during the era of the Galactic Empire, Marek originated from the Wookiee home planet of Kashyyyk as…
Description Davy Jones: You've been captain of the Black Pearl for 13 years. That was our agreement. Jack: Technically I was only captain for two years, then I was mutinied upon. Davy Jones: Then you were a poor captain, but a captain nonetheless. Ha…
GCD Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted Submission(s): Problem Description The greatest common divisor GCD(a,b) of two positive integers a and b,sometimes written (a,b),,)=,(,)=. (a,b) can be e…