cf-341C Iahub and Permutations】的更多相关文章

C. Iahub and Permutations time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Iahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permu…
转载请注明出处: 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…
C. Iahub and Permutations time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Iahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permu…
题目链接:http://codeforces.com/contest/340/problem/E E. Iahub and Permutations time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Iahub is so happy about inventing bubble sort graphs that he's sta…
Iahub and Permutations 题解: 令 cnt1 为可以没有限制位的填充数字个数. 令 cnt2 为有限制位的填充数字个数. 那么:对于cnt1来说, 他的值是cnt1! 然后我们对cnt2进行dp. 对于任意一个新加进来的数字,我们可以令一个一个没有限制位数放在这里, 那么新加进来的数字 ≍ 没有限制位, 他的方案为 i-1 * dp[i-1] , 然后我们如果把这个数字放到有限制位的数来说, 那么他的转移方程就和错排一样了. 代码: #include<bits/stdc++…
容斥原理,组合数. 找出有$cnt$个数字还有没放,那么总方案数就是$cnt!$. 总方案数里面包含了正确的和非正确的,我们需要将非正确的删去. 先删去$1$个数字$a[i]=i$的情况,发现会多删,要加回两个数字$a[i]=i$的情况,发现会多加......就是一个容斥原理的过程. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring>…
http://codeforces.com/contest/341/problem/C 题意: 有一个长度为n的排列a,其中有一些位置被替换成了-1.你需要尝试恢复这个排列,将-1替换回数字.求有多少种可行的替换方法,满足得到的是一个排列,且不存在ai = i的位置.n $\le$ 2000 感觉很巧妙的转化: $n$排列$\rightarrow\ n*n$的棋盘上放$rook$ 对角线是不能放的 我们把放了$rook$的行和列删除后,可以发现每列和每行最多一个不能放的位置 $f[i][j]$表…
Codeforces题号:#340E 出处: Codeforces 主要算法:思维+DP 难度:4.8 题意: 有一个长度为$n$的排列(即各元素互不相同),其中有一些为-1.现要求将数填到这些-1上,使得原排列是一个错位排列.问有几种方法? 思路分析: 又是一道超级难的DP…… 这不就是一个错排的模板题吗?不是只要看有几个-1就做多少的错排吗?确实,样例很不良心,那就给你一组反例吧…… 5 -1 -1 2 3 -1 我们注意到了,并不是剩下的元素全是错排.因为原来我们认为2不能处在2的位置,但…
给出一个长为n的数列的k个排列(1 ≤ n ≤ 1000; 2 ≤ k ≤ 5).求这个k个数列的最长公共子序列的长度 dp[i]=max{dp[j]+1,where j<i 且j,i相应的字符在k个排列中都保持同样的相对位置} #include <iostream> #include <vector> #include <cstring> #include <cstdio> #include <cmath> #include <al…
题目:http://codeforces.com/contest/1093/problem/E 只能想到转化成查询一个区间里值在一个范围里的数的个数…… 没有想到这样适合用主席树套树状数组维护.不过据说卡空间. 参考了这里的题解:https://www.luogu.org/problemnew/solution/CF1093E 写了CDQ分治.一个值在两个序列里的位置看成两维坐标的话,就是查平面区域内点的个数. 按 x (在第一个序列里的位置)排序,分治操作的时间,y (在第二个序列里的位置)用…
挺有收获的一道题ヾ(◍°∇°◍)ノ゙ 恰好为 m ,这个限制仿佛不是很好处理.一般而言,我所了解的恰好为 k 的条件,不是用组合数 / dp状态转移 / 斜率二分就只剩下容斥了.我们可以先处理出 num[i] 表示至少有 i 个完美位置的方案数,之后再容斥得到 ans[m] (恰好为 m 个).如何获得 num 数组?建立dp状态为 f[i][j][p][q], (其中p, q为01状态)表示dp到第 i 个位置,已经出现了 j 个完美的位置,且 i 和 i + 1 是否被用过.转移的时候分情况…
题意:给出一组排列,某些位置不知道(-1),要求求出有多少种还原方式,使得所有a[i]!=i /* 这是一道关于排列的动态规划,这种体大都可以当作棋盘来做,如果把i这个数放到第j个位置,那么就将棋盘的第i行第j列填入数字,最后使每一行每一列只有一个数. 我们从棋盘中删去已经填入数字的行和列,设删完后的棋盘为nn*nn,设mm为不能填数的位置数,f[i][j]代表i*i的棋盘有j个不能填数的位置的合法方案. 转移方程:f[i][j]=f[i][j-1]-f[i-1][j-1] 边界:f[i][0]…
挺水的一道题~ 拿全排列随便乘一下就好了. #include <cstdio> #include <algorithm> #define N 300004 #define ll long long #define mod 998244353 #define setIO(s) freopen(s".in","r",stdin) using namespace std; struct Node { int a,b; }t[N]; ll fac[N…
1. CF 438D The Child and Sequence 大意: n元素序列, m个操作: 1,询问区间和. 2,区间对m取模. 3,单点修改 维护最大值, 取模时暴力对所有>m的数取模. 因为取模后至少减半, 复杂度$O(nlognlogC)$ 2. CF 431E Chemistry Experiment 大意: n个试管, 第$i$个试管有$a_i$单位水银, m个操作: 1, 修改$a_x$改为$v$. 2, 将$v$单位水倒入试管, 求一种方案使得有水的试管水银与水总量的最大…
A.The Wall 题意:两个人粉刷墙壁,甲从粉刷标号为x,2x,3x...的小块乙粉刷标号为y,2y,3y...的小块问在某个区间内被重复粉刷的小块的个数. 分析:求出x和y的最小公倍数,然后做一个一维的区间减法就可以了. #include <cstdlib> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long L…
E. 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 important for Iahub. When Iahub goes away, Iahubina comes to h…
A. The Wall 求下gcd即可. B. Maximal Area Quadrilateral 枚举对角线,根据叉积判断顺.逆时针方向构成的最大面积. 由于点坐标绝对值不超过1000,用int比较快. C. Tourist Problem 假设序列为\(p_1,p_2,...,p_n\),则距离总和为\(,,,p_1,|p_2-p_1|,...,|p_n-p_{n-1}|\). 第1个点\(p_1\)的贡献为\(\sum a_i(n-1)!\) \(|p_i-p_{i-1}|\)的贡献为\…
CF 715 E. Complete the Permutations 题目大意:给定两个排列\(p,q\)的一部分.定义两个排列\(p,q\)的距离为使用最少的交换次数使得\(p_i=q_i\).对于所有\(0\leq k\leq n-1\)的所有补全方案中距离为\(k\)的方案数. \(\\\) 将排列看成置换的话,两个完整的排列的距离为\(n-m\),其中\(m\)为循环节个数. 现在考虑将所有存在的不完整的循环节找出来.先连边:对于每个\(i\),连\(a_i\to b_i\),然后若\…
E. Intersection of Permutations 链接 题意: 给定两个序列,询问第一个排列的[l1,r1]和第二个排列[l2,r2]中有多少个共同的数,支持在第二个排列中交换两个数. 分析: 首先求出一个数组,c[i],第二个排列的这个数字在第一个排列中出现的位置.那么查询就是询问c数组中的[l2,r2]中的有多少个数字的在[l1,r1]之间.此时可以差分+离线+树状数组在$nlogn$的时间复杂度内完成. 考虑修改操作,考虑cdq分治.在b排列中交换两个数,那么也就是c数组中交…
题链;http://codeforces.com/problemset/problem/251/B B. Playing with Permutations time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Little Petya likes permutations a lot. Recently his mom has p…
题目:http://codeforces.com/problemset/problem/610/E 如果存在c1,c2在原串相邻且在询问串中c1在c2前面的话,把它们在原串出现次数加起来记作sum,那么n-sum就是答案. 维护一棵线段树,线段树的每个节点存一个k^2的矩阵. 然后修改的话就在线段树上区间修改..(标记下传的时候要注意不要越界TAT... 然后询问的话就k^2搞一下需要被减掉的字符对就好了.. #include<cstring> #include<iostream>…
[CF715E]Complete the Permutations(容斥,第一类斯特林数) 题面 CF 洛谷 给定两个排列\(p,q\),但是其中有些位置未知,用\(0\)表示. 现在让你补全两个排列,定义两个排列\(p,q\)之间的距离为每次选择\(p\)中两个元素交换,使其变成\(q\)的最小次数. 求距离恰好为\([0,n-1]\)的填数方案数. 加强的题目在\(BZOJ\)上有,戳这里. 题解 看到这道题目就觉得无比熟悉.回头翻了翻发现果然是省队集训的时候的题目... 果然都是原题啊..…
[CF285E]Positions in Permutations(动态规划,容斥) 题面 CF 洛谷 题解 首先发现恰好很不好算,所以转成至少,这样子只需要确定完一部分数之后剩下随意补. 然后套一个二项式反演进行容斥就可以得到答案了. 考虑怎么算至少\(m\)个的贡献, 设\(f[i][j][S]\)表示当前填到了位置\(i\),一个有\(j\)个贡献,\(i\)和\(i+1\)的使用情况是\(S\)的方案数,每次枚举一下这个位置是填\(i+1\)还是\(i-1\)还是其他就可以进行转移了.…
CF Edu Round 71 A There Are Two Types Of Burgers 贪心随便模拟一下 #include<iostream> #include<algorithm> #include<cstring> #include<cstdio> using namespace std; #define MAXN 200006 int n , m; int A[MAXN]; int b , p , f , h , c; int main()…
凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:packet reader failure 2. 使用lsnrctl status检查监听,一直没有响应,这个是极少见的情况. 3. 检查数据库状态为OPEN,使用nmon检查系统资源.如下一张截图所示,CPU利用率不高,但是CPU Wait%非常高.这意味着I/O不正常.可能出现了IO等待和争用(IO…
Given a collection of numbers that might contain duplicates, return all possible unique permutations. For example,[1,1,2] have the following unique permutations: [ [1,1,2], [1,2,1], [2,1,1] ] 分析: 全组合的思想,保证start和end之间交换的时候中间没有与end相同的数字 class Solution…
Given a collection of numbers that might contain duplicates, return all possible unique permutations. For example,[1,1,2] have the following unique permutations:[1,1,2], [1,2,1], and [2,1,1]. 这道题是之前那道Permutations 全排列的延伸,由于输入数组有可能出现重复数字,如果按照之前的算法运算,会有…
Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1]. 这道题是求全排列问题,给的输入数组没有重复项,这跟之前的那道Combinations 组合项 和类似,解法基本相同,但是不同点在于那道不同的数字顺序只…
链接:http://poj.org/problem?id=2369 Permutations Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3039   Accepted: 1639 Description We remind that the permutation of some final set is a one-to-one mapping of the set onto itself. Less formal…
 cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....       其实这个应该是昨天就写完的,不过没时间了,就留到了今天.. 地址:http://codeforces.com/contest/651/problem/A A. Joysticks time limit per test 1 second memory limit per test 256…