leetcode4:Permutation
#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的更多相关文章
- Permutation Sequence
		The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ... 
- [LeetCode] Palindrome Permutation II 回文全排列之二
		Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ... 
- [LeetCode] Palindrome Permutation 回文全排列
		Given a string, determine if a permutation of the string could form a palindrome. For example," ... 
- [LeetCode] Permutation Sequence 序列排序
		The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ... 
- [LeetCode] Next Permutation 下一个排列
		Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ... 
- 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 ... 
- UVA11525 Permutation[康托展开 树状数组求第k小值]
		UVA - 11525 Permutation 题意:输出1~n的所有排列,字典序大小第∑k1Si∗(K−i)!个 学了好多知识 1.康托展开 X=a[n]*(n-1)!+a[n-1]*(n-2)!+ ... 
- 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 ... 
- Permutation
		(M) Permutations (M) Permutations II (M) Permutation Sequence (M) Palindrome Permutation II 
随机推荐
- session概要
			一.Session简单介绍 在WEB开发中,服务器可以为每个用户浏览器创建一个会话对象(session对象),注意:一个浏览器独占一个session对象(默认情况 下).因此,在需要保存用户数据时,服 ... 
- 使用centos官方镜像制作jdk8环境镜像
			首先将jdk文件或者tar包放在/var/local路径下 然后Dockerfile中写 # 以 centos7 为基础镜像 FROM centos:latest MAINTAINER chen # ... 
- TypeScript白鹭引擎Egret防止按钮事件冒泡穿透
			this.addEventListener(egret.TouchEvent.TOUCH_BEGIN, (event) => { if (event.target!=this) return;/ ... 
- C# SM加密
			using System; using System.Collections.Generic; using System.Linq; using System.Text; using Org.Boun ... 
- 开源一款强大的文件服务组件(QJ_FileCenter)(系列二 安装说明)
			系列文章 1. 开源一款强大的文件服务组件(QJ_FileCenter)(系列一) 2. 开源一款强大的文件服务组件(QJ_FileCenter)(系列二 安装说明) 3. 开源一款强大的文件服务组件 ... 
- hdu  X问题 (中国剩余定理不互质)
			http://acm.hdu.edu.cn/showproblem.php?pid=1573 X问题 Time Limit: 1000/1000 MS (Java/Others) Memory ... 
- Photoshop的脚本开发
			之前的博客的文章,贴过来了.PhotoshopCS开始增加了脚本.Photoshop的脚本可以用JavaScript,AppleScript以及VbScript和visualBasic.其中Apple ... 
- k8s rc
			RC是用来管理Pod的,每个RC由一个或多个Pod组成:在RC被创建之后,系统将会保持RC中的可用Pod的个数与创建RC时定义的Pod个数一致,如果Pod个数小于定义的个数,RC会启动新的Pod,反之 ... 
- 注意力机制(Attention Mechanism)应用——自然语言处理(NLP)
			近年来,深度学习的研究越来越深入,在各个领域也都获得了不少突破性的进展.基于注意力(attention)机制的神经网络成为了最近神经网络研究的一个热点,下面是一些基于attention机制的神经网络在 ... 
- SpringMVC 的映射
			27.1.1 @RequestMapping使用 之前,我们是把@RequestMapping注解放在方法之上,用来给方法绑定一个请求映射.除此以外,@RequestMapping注解还可以放在类的上 ... 
