F. Coprime Subsequences】的更多相关文章

题目链接: F. Coprime Subsequences time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Let's call a non-empty sequence of positive integers a1, a2... ak coprime if the greatest common divisor of al…
http://codeforces.com/contest/803/problem/F 这题正面做了一发dp dp[j]表示产生gcd = j的时候的方案总数. 然后稳稳地超时. 考虑容斥. 总答案数是2^n - 1 那么需要减去gcd = 2的,减去gcd = 3的,减去gcd = 5的.加上gcd = 6的,那么gcd  = 4的呢? 不用处理,因为这些在gcd = 2的时候减去就行.就是把他们的贡献统计到gcd = 2的哪里去. 然后这个 #include <cstdio> #inclu…
Let's call a non-empty sequence of positive integers a1, a2... ak coprime if the greatest common divisor of all elements of this sequence is equal to 1. Given an array a consisting of n positive integers, find the number of its coprime subsequences.…
Link:http://codeforces.com/contest/803/problem/F 题意:给n个数字,求有多少个GCD为1的子序列. 题解:容斥!比赛时能写出来真是炒鸡开森啊! num[i]: 有多少个数字是 i 的倍数. 所有元素都是1的倍数的序列有:$2^n-1$个.先把$2^n-1$设为答案 所有元素都是质数的倍数的序列有:$\sum 2^{num[p_1]} - 1$个,这些序列不存在的,得从答案中减去. 所有元素都是两质数之积的倍数的序列有:$\sum 2^{num[p_…
[题目链接]:http://codeforces.com/contest/803/problem/F [题意] 给你一个序列; 问你这个序列里面有多少个子列; 且这个子列里面的所有数字互质; [题解] 计算cnt[x]; 表示数组里有多少个数是x的倍数; 则某个子列里面所有的数字都能被x整除的子列个数为2cnt[x]−1 把这个值记为f[x]; 则我们用需要用容斥原理; 把所有能被2,3,..n整除的子列删除掉; 这里面会有重复计数的问题; 解决方式是,从大到小枚举f[x] 然后对于y=i*x的…
原题链接:http://codeforces.com/contest/803/problem/F 题意:若gcd(a1, a2, a3,...,an)=1则认为这n个数是互质的.求集合a中,元素互质的集合的个数. 思路:首先知道一个大小为n的集合有2n-1个非空子集,运用容斥,对某个数,我们可以求出它作为因子出现的个数(假设为ki).推一下式子,可以得到结果就等于:Σmiu[i]*(2i-1),其中miu[i]是莫比乌斯函数. 时间复杂度为:O(n*sqrt(max_a)),看起来似乎会超时,实…
$dp$. 记$dp[i]$表示$gcd$为$i$的倍数的子序列的方案数.然后倒着推一遍减去倍数的方案数就可以得到想要的答案了. #include <iostream> #include <cstdio> #include <cstring> #include <string> #include <cmath> #include <queue> #include <stack> #include <vector>…
Educational Codeforces Round 20  A. Maximal Binary Matrix 直接从上到下从左到右填,注意只剩一个要填的位置的情况 view code //#pragma GCC optimize("O3") //#pragma comment(linker, "/STACK:1024000000,1024000000") #include<bits/stdc++.h> using namespace std; fu…
Codeforces Round 363 Div. 1 题目链接:## 点击打开链接 A. Vacations (1s, 256MB) 题目大意:给定连续 \(n\) 天,每天为如下四种状态之一: 不能进行运动或比赛 可以进行运动但不能比赛 可以进行比赛但不能运动 可以进行比赛或运动 对于每天,可以根据当天的状态选择运动,比赛或休息.但不能连续两天的选择均为运动或均为比赛.求在这 \(n\) 天中最少需要休息多少天. 数据范围:\(n \leq 100\) 简要题解:令 \(f_{i,0},f_…
排名:http://acm.sdut.edu.cn/sd2012/2013.htm 解题报告:http://www.tuicool.com/articles/FnEZJb A.Rescue The Princess(几何,向量) B.The number of steps(记忆化搜索,概率dp) C.Boring Counting(划分树) D.A-Number and B-Number E.Alice and Bob F.Mountain Subsequences(dp) G.Rubik’s…
查询数据操作…
2013年山东省赛F题 Mountain Subsequences先说n^2做法,从第1个,(假设当前是第i个)到第i-1个位置上哪些比第i位的小,那也就意味着a[i]可以接在它后面,f1[i]表示从第一个开始,以a[i]为结尾的不同递增序列的个数,要加上1,算上本身.正反各跑一遍,答案加一下(f1[i]-1)*(f2[i]-1)优化就是,比a[i]小的,只有a[i]-1个 #include<iostream> #include<cstdio> #include<queue&…
题目链接 题目大意 给你一个长为d只包含字符'a','b','c','?' 的字符串,?可以变成a,b,c字符,假如有x个?字符,那么有\(3^x\)个字符串,求所有字符串种子序列包含多少个abc子序列 题目思路 假如没有问号,那么就是一个简单的dp \(dp[i][1]为前i个位置有多少个a\) \(dp[i][2]为前i个位置有多少个ab\) \(dp[i][3]为前i个位置有多少个abc\) 考虑 '?' 会对 dp 的转移产生什么影响,因为 '?' 可以将三种字母全部都表示一遍,所以到了…
https://leetcode.com/problems/distinct-subsequences/ Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence of a string is a new string which is formed from the original string by deleting some (can be non…
CO-PRIME 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 This problem is so easy! Can you solve it? You are given a sequence which contains n integers a1,a2……an, your task is to find how many pair(ai, aj)(i < j) that ai and aj is co-prime.   输入 There are mu…
Problem F "Folding" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100002 Description Bill is trying to compactly represent sequences of capital alphabetic characters from 'A' to 'Z' by folding repeating subsequences insid…
CO-PRIME 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描写叙述 This problem is so easy! Can you solve it? You are given a sequence which contains n integers a1,a2--an, your task is to find how many pair(ai, aj)(i < j) that ai and aj is co-prime. 输入 There are mult…
Friends and Subsequences Mike and !Mike are old childhood rivals, they are opposite in everything they do, except programming. Today they have a problem they cannot solve on their own, but together (with you) — who knows? Every one of them has an int…
Subsequences Summing to Sevens 题目描述 Farmer John's N cows are standing in a row, as they have a tendency to do from time to time. Each cow is labeled with a distinct integer ID number so FJ can tell them apart. FJ would like to take a photo of a conti…
[抄题]: 给出字符串S和字符串T,计算S的不同的子序列中T出现的个数. 子序列字符串是原始字符串通过删除一些(或零个)产生的一个新的字符串,并且对剩下的字符的相对位置没有影响.(比如,“ACE”是“ABCDE”的子序列字符串,而“AEC”不是). Here is an example:S = "rabbbit", T = "rabbit" Return 3. [思维问题]: [一句话思路]: 由于要查找T.最后一位相同时可以同时删,不相同时只能删S,不能多删除T.…
Co-prime Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 935    Accepted Submission(s): 339 Problem Description Given a number N, you are asked to count the number of integers between A and B in…
Heap Partition Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge A sequence S = {s1, s2, ..., sn} is called heapable if there exists a binary tree T with n nodes such that every node is labelled with exactly one element from the se…
[题目]G. Coprime Arrays [题意]当含n个数字的数组的总gcd=1时认为这个数组互质.给定n和k,求所有sum(i),i=1~k,其中sum(i)为n个数字的数组,每个数字均<=i,总gcd=1的方案数.n<=2*10^6.答案将所有sum(i)处理成一个数字后输出. [算法]数论(莫比乌斯反演) [题解]假设当前求sum(k),令f(i)表示gcd=i的数组方案数,F(i)表示i|gcd的数组的方案数. 因为F(x)=Σx|df(d),由莫比乌斯反演定理,f(x)=Σx|d…
F. Consecutive Subsequence time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given an integer array of length nn. You have to choose some subsequence of this array of maximum length…
Discipntion Let's call an array a of size n coprime iff gcd(a1, a2, ..., an) = 1, where gcd is the greatest common divisor of the arguments. You are given two numbers n and k. For each i (1 ≤ i ≤ k) you have to determine the number of coprime arrays …
Description There are n people standing in a line. Each of them has a unique id number. Now the Ragnarok is coming. We should choose 3 people to defend the evil. As a group, the 3 people should be able to communicate. They are able to communicate if…
Do you know what is called ``Coprime Sequence''? That is a sequence consists of nnpositive integers, and the GCD (Greatest Common Divisor) of them is equal to 1. ``Coprime Sequence'' is easy to find because of its restriction. But we can try to maxim…
题目链接: D. Friends and Subsequences time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output Mike and !Mike are old childhood rivals, they are opposite in everything they do, except programming. Toda…
Co-prime Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description Given a number N, you are asked to count the number of integers between A and B inclusive which are relatively prime to N.Two integers ar…
CO-PRIME 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描写叙述 This problem is so easy! Can you solve it? You are given a sequence which contains n integers a1,a2--an, your task is to find how many pair(ai, aj)(i < j) that ai and aj is co-prime. 输入 There are mult…