#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. Python学习之全局变量与global

    刚学习Python,遇到个问题:为什么有些定义在函数外的变量可以直接被函数使用,有些就不行呢? 如: count = 0 def change(): count += 1 change() # 报错 ...

  2. django drf 级联数据和RetrieveModelMixin

    1.定义View from django.shortcuts import render from rest_framework.views import APIView from rest_fram ...

  3. Linq的Join == 两个foreach

    因为实在太懒了,很久没动笔,今天强迫自己写一个小短篇. 之前讨论过用SelectMany代替两重的foreach循环.今天我们看一下Join和foreach的关系. 首先是Join的定义 public ...

  4. FIM控制同步用户

     C:\Program Files\Microsoft Office Servers\15.0\Synchronization Service\UIShell 这个路径下,你如果懂FIM,可以进去看看 ...

  5. Android : M 与 N 的权限管理

    从 M 开始,permission 分为 Normal permission Runtime permission Normal permission 直接在 manifest 里声明就可以用了. a ...

  6. c语言------第一次作业,分支,顺序结构

    1.1思维导图 1.2本章学习体会及代码量学习体 1.2.1学习体会 初次接触C语言,由于比较懒惰,感觉学习脚步跟不上身边的同学,也比较困扰.但伴随着pta上多次显示的##编译错误##,坚持不懈地问舍 ...

  7. 467. Unique Substrings in Wraparound String

    Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...

  8. Java中 IO类 - File类中的判断功能

    package com.hxzy.IOSer;import java.io.*;public class Demo05 { public static void main(String[] args) ...

  9. Java新手学习路线

      转自网络     分享个JAVA学习路线[新手可以参考看下]觉得不好的,大家可以提出来我补充. 第一阶段 技术名称 技术内容 J2SE(java基础部分) java开发前奏 计算机基本原理,Jav ...

  10. ROS(URDF机器人建模)

    新建功能包mbot_description 在功能包下新建文件config,launch,meshes,urdf. 在launch文件夹下新建文件display_mbot_base_urdf.laun ...