codeforces 361 D - Friends and Subsequences】的更多相关文章

原题: Description 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 integer sequ…
C. Subsequences Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/problem/C Description For the given sequence with n different elements find the number of increasing subsequences with k + 1 elements. It is guaranteed tha…
题目链接:http://codeforces.com/contest/361/problem/D 题意:最多可以修改K次数字,每次修改一个数字变成任意值,C=max(a[i+1]-a[i]):求操作之后最小的C. 题解:由于n和k比较小其实可以考虑一下区间dp,但是如果区间dp要求的话估计是要3维的显然会炸掉. 于是可以考虑一下二分一下结果c的值,为什么要考虑二分呢?主要是由于c的值与修改的次数是成正比的 显然改的越多c值肯定越少,所以可以二分.然后就是如何判断是否满足条件了,这里要用到dp,设…
题目链接:http://codeforces.com/contest/361/problem/C 题意:对一个数列有这么两个操作 1.(1,l,r,p)..将区间[l,r]所有数都加上p 2.(2,l,r,m).求出区间[l,r]的最大值为m 现在告诉这么一些操作(<5000个),问能否找到一个原始的数列,有则输出YES与这个数列,否则输出NO,答案可能不唯一输出任何合法的都行. 题解:先给数组赋予最大的初值然后倒着处理,遇到1就减去.如果是2,将这一区间里所有数都去min(自身,MAX) 处理…
A题((Mike and Cellphone) 看起来好像需要模拟数字键位的运动,可是,只要判断出那些必然YES的数字组合不就好了么 #include <cstdio> #include <iostream> #include <cstring> using namespace std; ]; inline bool judge() { ]&&vis[]) return true; ]&&vis[]) return true; ]&…
C. Subsequences     For the given sequence with n different elements find the number of increasing subsequences with k + 1 elements. It is guaranteed that the answer is not greater than 8·1018. Input   First line contain two integer values n and k (1…
题目链接: 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…
[题目链接]:http://codeforces.com/problemset/problem/314/C [题意] 让你从n个元素的数组中选出所有的不同的非递减子数列; 然后计算比这个子数列小的和它的长度一样长的数列的个数; "小"的定义在题目里有说; [题解] 设dp[i]表示以i作为非递减子数列的最后一个数的比它小的数列的个数; 则有递推式 dp[i] = (dp[1]+dp[2]+-+dp[i])*i+i; 写个树状数组,来快速求和就好; 要写出原数组,维护原数组; 不然求dp…
Friends and Subsequences 题解: 如果左端点来说, 那么对于a[i]来说是向上的一条折线, b[i]来说是向下的一条折线, 那么如果这2个折线求交点个数的话, 我们可以二分去求第一个 a[i] == b[i] 的地方, 求最后一个a[i] == b[i]的地方. 代码: #include<bits/stdc++.h> using namespace std; #define Fopen freopen("_in.txt","r",…
原题: Description Mike wants to prepare for IMO but he doesn't know geometry, so his teacher gave him an interesting geometry problem. Let's define f([l, r]) = r - l + 1 to be the number of integer points in the segment [l, r] with l ≤ r (say that ). Y…
原题: Description While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, loc…
原题: Description Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight seeing in the city. City consists of n intersections numbered from 1 to n. Mike starts walking from his house locate…
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u   Description Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible! Aside from loving sweet things, thieves from this…
time limit per test2 seconds memory limit per test512 megabytes inputstandard input outputstandard output Mike and !Mike are old childhood rivals, they are opposite in everything they do, except programming. Today they have a problem they cannot solv…
前面说点什么.. 为了完成日常积累,傻逼呵呵的我决定来一发codeforces 挑水题 泛做.. 嗯对,就是泛做.. 主要就是把codeforces Div.1的ABCD都尝试一下吧0.0.. 挖坑0.0.. Codeforces Round #360 A. NP-Hard Problem 就是一个二分图染色,判断是否为二分图而已.. B. Remainders Game 题意:有一个未知的\(x\)和已知\(x\ mod\ c_i\)的值,问是否能确定\(x\ mod\ k\)的值 考虑一下中…
D. Friends and Subsequences 题目连接: http://www.codeforces.com/contest/689/problem/D Description 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 o…
题目大意:给你两个长度为n的数组a, b,问你有多少个问你有多少个区间满足 a中最大值等于b中最小值. 思路:我本来的想法是用单调栈求出每个点的管辖区间,然后问题就变成了巨麻烦的线段覆盖问题,就爆炸写了 一晚上假算法.正解就是枚举一个端点,然后二分找右端点的区间,因为满足一个很神奇的单调性,然后st表维护 一下区间最值就好了. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #def…
codeforces 497E Subsequences Return 想法 做完这题,学了一些东西. 1.求一个串不同子序列个数的两种方法.解一 解二 2.这道题 \(n\) 很大,很容易想到矩阵加速,但是之前遇到的矩阵的题目,矩阵都是相同的,这题的矩阵虽然不同,但是至多 \(k\) 个,并且出现规律与 \(0\) ~ \(n-1\) 的 \(k\) 进制形态有关.题解中基于这点进行的优化和 \(dp\) 的思想又很像. 代码 #include<bits/stdc++.h> using na…
题目链接: C. Subsequences time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output For the given sequence with n different elements find the number of increasing subsequences with k + 1 elements. It is…
D - Friends and Subsequences Description 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…
题目链接:http://codeforces.com/contest/597/problem/C 给你n和数(1~n各不同),问你长为k+1的上升自序列有多少. dp[i][j] 表示末尾数字为i 长度为j的上升子序列个数,但是dp数组是在树状数组的update函数中进行更新. update(i, val, j)函数表示在i的位置加上val,更新dp[i][j]. sum(i, j)就是求出末尾数字小于等于i 且长度为j的子序列有多少个. //#pragma comment(linker, "/…
A - Mike and Cellphone 问有没有多解,每个点按照给出的序列用向量法跑一遍 #include<cstdio> #include<cstring> #include<queue> #include<cstdlib> #include<algorithm> #include<vector> #include<cmath> #include<map> using namespace std; ty…
A 脑筋急转弯 // #pragma comment(linker, "/STACK:1024000000,1024000000") #include <iostream> #include <cstdio> #include <cstring> #include <sstream> #include <string> #include <algorithm> #include <list> #incl…
Friends and Subsequences 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/H Description 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 the…
ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #include <cmath> #include <cstdio> #include <cstring> #include <cstdlib> #include <ctime> #include <set> #include <map>…
ST算法介绍:[转自http://blog.csdn.net/insistgogo/article/details/9929103] 作用:ST算法是用来求解给定区间RMQ的最值,本文以最小值为例 方法:ST算法分成两部分:离线预处理 (nlogn)和 在线查询(O(1)).虽然还可以使用线段树.树状链表等求解区间最值,但是ST算法要比它们更快,而且适用于在线查询. (1)离线预处理:运用DP思想,用于求解区间最值,并保存到一个二维数组中. (2)在线查询:对给定区间进行分割,借助该二维数组求最…
题目连接:http://codeforces.com/contest/688/problem/C 题意:给你一些边,问你能否构成一个二分图 题解:二分图:二分图又称作二部图,是图论中的一种特殊模型. 设G=(V,E)是一个无向图,如果顶点V可分割为两个互不相交的子集(A,B),并且图中的每条边(i,j)所关联的两个顶点i和j分别属于这两个不同的顶点集(i in A,j in B),则称图G为一个二分图. 直接上一个DFS就搞定了 #include<cstdio> #include<set…
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_…
For the given sequence with n different elements find the number of increasing subsequences with k + 1elements. It is guaranteed that the answer is not greater than 8·1018. Input First line contain two integer values n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 10)…
Sereja has a sequence that consists of n positive integers, a1, a2, ..., an. First Sereja took a piece of squared paper and wrote all distinct non-empty non-decreasing subsequences of sequence a. Then for each sequence written on the squared paper, S…