codeforces 651B Beautiful Paintings】的更多相关文章

B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes…
A. Joysticks time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at…
题意: 给定序列,重新排序,使严格上升的子序列最多.求这些子序列总长度. 分析: 贪心,统计每个元素出现次数,每次从剩余的小的开始抽到大的,直到不再剩余元素. 代码: #include<iostream> #include<algorithm> using namespace std; const int maxn = 1005; int a[maxn]; int m[maxn]; int main (void) { int n;cin>>n; for(int i =…
题意:后一个比前一个大就加一,问最大次数. #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<cstdlib> #include<string> #include<cmath> #include<vector> using namespace std; ; ; ); const int inf =…
651B Beautiful Paintings 651A Joysticks 点击可查看原题 651B是一个排序题,只不过多了一步去重然后记录个数.每次筛一层,直到全为0.从这个题里学到一个正确姿势:给定一个排好序的的数组,怎么把它变成一个去重加权的新数组. 只需要一个while循环+一个指针. #define N 10 #include<iostream> using namespace std; int main() { ,,,,,,,,,}; int b[N]={}; int c[N]…
B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes…
B. Beautiful Paintings 题目连接: http://www.codeforces.com/contest/651/problem/B Description There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting…
B. Beautiful Paintings   time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becom…
B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes…
Codeforces 55D Beautiful Number a positive integer number is beautiful if and only if it is divisible by each of its nonzero digits. Input The first line of the input contains the number of cases t (1 ≤ t ≤ 10). Each of the next t lines contains two…
传送门 参考资料: [1]:CodeForces 55D Beautiful numbers(数位dp&&离散化) 我的理解: 起初,我先定义一个三维数组 dp[ i ][ j ][ k ]:来到 i 位置时,所有非零数的lcm = j,当前数位 k 时含有的 Beautiful numbers 的个数. 但是,由题意得,当前的数 k 可以是个很大的数(9e18),数组根本就开不下,那怎么办呢? 将当前的数 hash 一下,如何hash呢? 假设 a,b,c,d 为[0,9]的数,那么不存…
Codeforces 55D. Beautiful numbers 题意 求[L,R]区间内有多少个数满足:该数能被其每一位数字都整除(如12,24,15等). 思路 一开始以为是数位DP的水题,觉得只需要记录搜到当前位出现了哪些数字作为状态即可,明显是假算法...感觉这是一道数位DP好题.可以这样思考:一个数要想被其各位数字分别都整除,等价于它被那些数字的LCM整除.因此记录当前位,当前数对(1~9的LCM)取模的结果,当前出现的数字的LCM这三个值作为状态才合理,即dp[pos][sum][…
题目大意: 给定集合,对于任意一个的排列,记,求. 很明显每次搞出一个长度为的最长上升序列,然后把元素给删掉,答案增加. 直接暴力需要. 但是可以进行优化. 设有个,将个数从小到大排序,记为长度为的数组. 则答案为 于是可以优化到. #include <cstdio> #include <cctype> #include <algorithm> using namespace std; const int T=1001; int n; int a[T],len; inl…
大意: 给定序列$a$, 可以任意排序, 求最大下标i的个数, 满足$a_i<a_{i+1}$. 这个贪心挺好的, 答案就为n-所有数字出现次数最大值.…
D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer number is beautiful if…
Codeforces 题面传送门 & 洛谷题面传送门 一道名副其实(beautiful)的结论题. 首先看到这道设问方式我们可以很自然地想到套用斐波那契数列的恒等式,注意到这里涉及到 \(F_{a+id}\),因此考虑斐波那契数列组合恒等式 \(F_{m+n+1}=F_mF_{n}+F_{m+1}F_{n+1}\),具体证明戳这里,这里就不再赘述了. 注意到此题还涉及后 \(18\) 位,也就是要将斐波那契数列的各种运算放到模 \(10^{18}\) 意义下进行,因此我们可以考虑找一下斐波那契数…
D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer number is beautiful if…
把数位dp写成记忆化搜索的形式,方法很赞,代码量少了很多. 下面为转载内容:  a positive integer number is beautiful if and only if it is divisible by each of its nonzero digits.    问一个区间内[l,r]有多少个Beautiful数字    范围9*10^18        数位统计问题,构造状态也挺难的,我想不出,我的思维局限在用递推去初始化状态,而这里的状态定义也比较难    跟pre的…
893B Beautiful Divisors 思路: 打表 代码: #include <bits/stdc++.h> using namespace std; #define _for(i,a,b) for(int i=(a); i<(b); ++i) #define _rep(i,a,b) for(int i=(a); i<=(b); ++i) int a[8]={1,6,28,120,496,2016,8128,32640}; int main() { int n; scan…
There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one. We are allowed to arranged pictures in any order. What is the m…
题目链接:Beautiful Graph 题意:给定一张无向无权图,每个顶点可以赋值1,2,3,现要求相邻节点一奇一偶,求符合要求的图的个数. 题解:由于一奇一偶,需二分图判定,染色.判定失败,直接输出0.成功的话,统计下奇数(cnt1)和偶数(cnt2)顶点个数,只有奇数有两种,也就是说有$2^{cnt1}$种,但是可以把奇数和偶数顶点翻转,奇变偶,偶变奇,即最后有$2^{cnt1}+2^{cnt2}$种,注意此图可能不连通,各个图之间的答案数要相乘. #include <set> #inc…
time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he pa…
题目链接:http://codeforces.com/problemset/problem/665/E (http://www.fjutacm.com/Problem.jsp?pid=2255) 题意:找出有多少个连续的区间[l,r](1  ≤  l  ≤  r  ≤  n),该区间中所有的数的异或值大于等于k: 思路:首先,如果是单看题目的话,会发现暴力的话复杂度是O(n^3),但是我们先预处理异或前缀和,然后你会发现[l,r]区间的异或和等于s[l-1]^s[r],这样就可以O(n^2)的求…
题目链接: http://codeforces.com/contest/665/problem/E 题意: 求异或值大于给定K的区间个数. 分析: 首先我们可以得到区间前缀的异或值. 这样我们将这个前缀M和K一起走trie树,如果该位K的值为0,那么无论怎么走最后得到的答案都不会比K小,所以直接加上另一边的子树大小,然后继续沿着当前边走.如果该位K的值为1,那么想要大于等于K必须沿着另一边贪心的走. 代码: #include<cstdio> #include<iostream> u…
题目链接:https://vjudge.net/problem/CodeForces-55D D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Volodya is an odd boy and his taste is strange as well. It seems to him…
C. Beautiful Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal…
题目链接:http://codeforces.com/problemset/problem/55/D 题意:一个美丽数就是可以被它的每一位的数字整除的数. 给定一个区间,求美丽数的个数. 显然这是一道数位dp,就是满足一个数能被所有位数的lcm整除即可. 一般都会设dp[len][mod][LCM],mod表示余数,LCM表示前len位的lcm. 但是如果直接裸mod会很复杂,于是再想lcm{0,1,2,3,4,5,6,7,8,9}=2520; 而且lcm{a,b,c,d....}{a,b,c,…
一道挺难的概率期望dp,花了很长时间才学会div2的E怎么做,但这道题是另一种设法. https://codeforces.com/contest/1264/problem/C 要设为 \(dp_i\) 表示第 \(i\) 个格子期望经过多少次,所以 \(dp_{n+1}=1\). https://www.cnblogs.com/suncongbo/p/11996219.html…
链接: https://vjudge.net/problem/CodeForces-55D 题意: Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer number is beautiful if and only if it is divisible by each of its nonzero digits. We will not argue with…
Codeforces 题面传送门 & 洛谷题面传送门 首先对于这样的题目,我们应先考虑如何计算一个括号序列 \(s\) 的权值.一件非常显然的事情是,在深度最深的.是原括号序列的子序列的括号序列中,必定存在一个满足前面只由一段左括号,后面只由一段右括号组成,因此我们考虑枚举这中间位置在原括号序列中对应哪个位置,那么假设这个断点位于 \(i\) 和 \(i+1\) 之间,我们设 \(i\) 及之前有 \(x\) 个左括号,\(i+1\) 及之后有 \(y\)​​ 个右括号,那么显然以这个位置为端点…