#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. TSQL--NULL值和三值逻辑

    在SQL SERVER 中逻辑表达式存在三种值:TRUE+FALSE+UNKNOWN.UNKNOW可以理解为不确定,既不是TRUE又不是FALSE的表达式,主要由与NULL相关的逻辑判断引起,值为NU ...

  2. js自执行函数、调用递归函数、圆括号运算符、函数声明的提升

    前言 起因是我要在jquery的ajax中需要根据返回值来决定是否继续发起ajax请求,这是一个有条件的循环,符合条件就跳出.可以使用while循环的,但是想了想还是递归调用好用. 调用递归函数 递归 ...

  3. jQuery查找标签--选择器,筛选器,模态对话框, 左侧菜单栏

    查找标签 选择器: 基本选择器(同css) id选择器 $("#id") 标签选择器 $('tagName') class选择器 $(".className") ...

  4. 微信小店调用api代码示例

    刚开始调用微信小店api的时候,可能大家会遇到问题.系统总是提示system error,归根结底还是发送的参数不正确. 下面给出几个调用例子: 例子写得不全. <?php function c ...

  5. 六、linux目录结构知识

    1.显示行号: cat -n 2.set    nu 3.tail -f  a.txt  查看文件的尾部变化 4.w  当前的登陆用户 5.yum包管理工具底层调用的还是  rpm  -ivh  包名 ...

  6. H - Graphics(dfs)

    H - Graphics   Time Limit:1000MS     Memory Limit:131072KB     64bit IO Format:%lld & %llu Submi ...

  7. 【OCP题库-12c】最新CUUG OCP 071考试题库(72题)

    72.View the exhibit for the structure of the STUDENTand FACULTYtables. STUDENT Name Null? Type ----- ...

  8. 【OCP|052】OCP 11g最新考题收集整理-第6题

    6.You are installing Oracle Grid Infrastructure by using the Oracle Universal Installer (OUI). You s ...

  9. “全栈2019”Java多线程第二章:创建多线程之继承Thread类

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java多 ...

  10. WC2019 全国模拟赛第一场 T1 题解

    由于只会T1,没法写游记,只好来写题解了... 题目链接 题目大意 给你一个数列,每次可以任取两个不相交的区间,取一次的贡献是这两个区间里所有数的最小值,求所有取法的贡献和,对 \(10^9+7\) ...