UVA - 11077 Find the Permutations (置换)】的更多相关文章

Sorting is one of the most usedoperations in real life, where Computer Science comes into act. It iswell-known that the lower bound of swap based sorting is nlog(n).It means that the best possible sorting algorithm will take at least W(nlog(n))swaps…
UVA 11077 - Find the Permutations option=com_onlinejudge&Itemid=8&page=show_problem&category=485&problem=2018&mosmsg=Submission+received+with+ID+13900478" target="_blank" style="">题目链接 题意:给定n,k求出有多少个包括元素[1-n…
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=35431 [思路] 置换+递推 将一个排列看作一个置换,分解为k个循环,则最少需要n-k次交换(循环内部交换)即可排序. 设f[i][j]表示将i个数至少交换j次排序完成的方案数,则有转移方程: f[i][j] = f[i-1][j]+(i-1)*f[i-1][j-1] 分别表示独立成为一个循环与加入前i-1个循环. [代码] #include<cstdio> #…
                           Find the Permutations Sorting is one of the most used operations in real life, where Computer Science comes into act. It iswell-known that the lower bound of swap based sorting is nlog(n). It means that the best possiblesor…
题意: 给定$n$和$k$,问有多少排列交换$k$次能变成升序 $n \le 21$ $uva$貌似挂掉了$vjudge$上一直排队 从某个排列到$1,2,...,n$和从$1,2,...,n$到某个排列是一样的 排列就是置换,分解循环,然后显然每个循环变成升序需要$len-1$次交换 然后有$t$个循环的置换需要$n-t$次交换 $DP$就行了$f[i][j]$表示前$i$个数有$j$个循环 其实可以发现就是第一类$stirling$数 注意:以后一定要测一遍极限会爆$long\ long$…
题意:给定 n 和 m,问你在 1 ~ n 的所有排列中,有多少个排列满足至少要交换 m 次才能变成 1 2 3 ... n. 析:首先,先考虑一下,某个排列,要变成 1 2 3 .. n,最少要交换几次,这个问题,我们可以把这个排列拆成几个循环,很明显在每个循环中,假设循环长度是 n ,那么至少要交换 n-1 次才能完成,如果不理解的,可以自己举个例子看看,有这个条件,那么就好做了,dp[i][j] 表示 1  ~ i 的排列中至少要交换 j 次才能变成 1 2 3 .. i,dp[i][j]…
LA 3641 Leonardo的笔记本 题目 给出26个大写字母的置换B,问是否存在要给置换A,使得 \(A^2 = B\) 分析 将A分解为几个循环,可以观察经过乘积运算得到\(A^2\)后,循环有什么不同.将循环画成一个环,给他们标号\(0,1,\cdots,n-1\), 0号指向1号,n-1号指向1号.如果 n 是奇数,那么可以发现\(A^2\)中,0号指向了2号,2号指向了4号...n-1号指向了1号,1号指向3号...n-2号指向0号,他们依然是一个环.但是如果 n 是偶数,那么0号…
Find the Permutations Sorting is one of the most used operations in real life, where Computer Science comes into act. It is well-known that the lower bound of swap based sorting is nlog(n). It means that the best possible sorting algorithm will take…
把{1, 2, 3,,, n}叫做自然排列 本题便是求有多少个n元排列P要至少经过k次交换才能变为自然排列. 首先将排列P看做置换,然后将其分解循环,对于每个长度为i的循环至少要交换i-1次才能归位. 设有d(i, j)个i元排列至少交换j次才能变成自然排列. 则有d(i, j) = d(i-1, j) + d(i-1, j-1) * (i-1) 对于元素i有两种选择,自己成一个长度为1的循环,此时交换次数不变: 或者加到前面任意一个循环的任意一个位置,有i-1中情况,因为所加入的循环长度加一,…
/** 给定一个置换,看能不能存在一个置换A^2 = B 思路; 循环节长度为偶数n的置换只能由循环节长度为长度2*n 的置换A*A 而变得.所以只需求出循环节,看循环节长度为偶数的个数是否为偶数个即可.. 训练指南 **/ #include <iostream> #include <cstdio> #include <cstring> using namespace std; ; unsigned long long f[maxn][maxn]; int main()…