#include <utility>
#include <iostream>
#include <vector>
#include <algorithm>
//the next permutation
template<class BidirIt>
bool STL_next_permutation(BidirIt first, BidirIt last)
{
if (first == last) return false;
BidirIt i = last;
if (first == --i) return false; while () {
BidirIt i1, i2; i1 = i;
--i;
if (*i < *i1) {
i2 = last;
while (!(*i < *--i2))
;
std::iter_swap(i, i2);
std::reverse(i1, last);
return true;
}
if (i == first) {
std::reverse(first, last);
return false;
}
}
}
void nextPermutation(int A[],int len)
{
STL_next_permutation(A, A+len);
} //full pemutation
void fullPerm(int A[],int m,int n)
{
if(m == n)
{
for(int i=;i<n+;i++)
std::cout << A[i] << " ";
std::cout << std::endl;
return;
}
else
{
for(int i=m;i<n+;i++)
{
std::swap(A[m], A[i]);
fullPerm(A,m+,n);
std::swap(A[m], A[i]);
}
}
} int Factorial(int n)
{
int fac=;
for(int i=;i<=n;i++)
{
fac *=i;
}
return fac;
}
//康托编码第k个序列
void CantorCode(int A[],int len,int k)
{
--k;
std::vector<std::pair<int,bool>> v;
for(int i=;i<len;i++)
{
v.emplace_back(A[i],false);
} for(int i=;i<len;i++)
{
int j;
int t=k/Factorial(len-i-);
for(j=;j<len;j++)
{
if(!v[j].second)
{
if(t==) break;
--t;
}
}
A[i]=v[j].first;
v[j].second=true;
k=k%Factorial(len-i-);
}
}

leetcode4:Permutation的更多相关文章

  1. Permutation Sequence

    The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  2. [LeetCode] Palindrome Permutation II 回文全排列之二

    Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...

  3. [LeetCode] Palindrome Permutation 回文全排列

    Given a string, determine if a permutation of the string could form a palindrome. For example," ...

  4. [LeetCode] Permutation Sequence 序列排序

    The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  5. [LeetCode] Next Permutation 下一个排列

    Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...

  6. Leetcode 60. Permutation Sequence

    The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  7. UVA11525 Permutation[康托展开 树状数组求第k小值]

    UVA - 11525 Permutation 题意:输出1~n的所有排列,字典序大小第∑k1Si∗(K−i)!个 学了好多知识 1.康托展开 X=a[n]*(n-1)!+a[n-1]*(n-2)!+ ...

  8. Permutation test: p, CI, CI of P 置换检验相关统计量的计算

    For research purpose, I've read a lot materials on permutation test issue. Here is a summary. Should ...

  9. Permutation

    (M) Permutations (M) Permutations II (M) Permutation Sequence (M) Palindrome Permutation II

随机推荐

  1. Android Camera的使用(一) 读书笔记

    原文地址 https://blog.csdn.net/junzia/article/details/52301199 拍照步骤1.添加权限2.开启相机时check一下是否有摄像头3.对预览大小.照片大 ...

  2. MVC v5.1 Preview 包含 web api 2.1 web pages 3.1

    Includes ASP.NET MVC 5.1, Web API 2.1, and Web Pages 3.1 preview release. This was released marked a ...

  3. .Net Core Runtime安装说明

    在开发阶段,都是直接安装.Net Core的SDK,但是在部署的时候你还是直接装SDK吗?当然直接装SDK也没什么问题,也可以少一些麻烦.但是如果你像我一样不喜欢在产线上装SDK,只想装Runtime ...

  4. windows 10 RelativePanel

    The new RelativePanel implements a style of layout that is defined by the relationships between its ...

  5. 63. 不同路径 II leetcode JAVA

    题目 一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为“Start” ). 机器人每次只能向下或者向右移动一步.机器人试图达到网格的右下角(在下图中标记为“Finish”). 现在 ...

  6. BZOJ4012 [HNOI2015]开店 (动态点分治)

    Description 风见幽香有一个好朋友叫八云紫,她们经常一起看星星看月亮从诗词歌赋谈到 人生哲学.最近她们灵机一动,打算在幻想乡开一家小店来做生意赚点钱.这样的 想法当然非常好啦,但是她们也发现 ...

  7. LOJ#3084. 「GXOI / GZOI2019」宝牌一大堆(递推)

    题面 传送门 题解 为什么又是麻将啊啊啊!而且还是我最讨厌的爆搜类\(dp\)-- 首先国士无双和七对子是可以直接搞掉的,关键是剩下的,可以看成\(1\)个雀头加\(4\)个杠子或面子 直接\(dp\ ...

  8. CTF中密码学一些基础【三】

    本文作者:i春秋签约作家——MAX. 看看今天教程: 看着几个字符在键盘的位置,直接就是三个圈圈,圆心的三个字符就是答案 非常简单! 答案就是KEY 看题解密就好了!! 根据提示Asp encode解 ...

  9. Getting Started with Elastic Search in .NET

    I have been working on many application during my career.  Many if not all had some searching capabi ...

  10. JavaScript 函数声明,函数表达式,匿名函数的区别,深入理解立即执行函数(function(){…})()

    function fnName(){xxxx}; // 函数声明:使用function关键字声明一个函数,在指定一个函数名. //例如:(正常,因为 提升 了函数声明,函数调用可以在函数声明之前) f ...