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
随机推荐
- 个人介绍&我的GitHub注册经历&初步使用
(1)个人介绍 我叫刘雨恬,目前是南通大学计科院网络工程141班的一名大二的学生,学号1413042004.由于学习软件工程的需要,我注册了cnblogs的这个博客账号,方便以后的学习交流.在兴趣爱好 ...
- wp8.1 创建动态磁贴应用
目前Windows Phone 8.1所支持磁贴像素大小有71x71.150x150和310x150,分为大中小三种模式,对于桌面磁贴微软提供的诸多模板http://msdn.microsoft.co ...
- c#进阶之lambda表达式
阅读之前,先确保对委托有基本的了解,传送门 c#进阶之浅析委托和事件. lambda表达式雏形第一步 在委托那篇文章,绑定的的方法都是具名函数,为了简化书写,可以换成匿名函数 public deleg ...
- iOS View 外层奇怪的黑线
最近碰到一个问题,当时是为了建了一个能自动适应内容的 Label.根据内容,我计算出需要的尺寸,然后把新尺寸设置给 Label. 但是显示的时候,一个奇怪的现象出现了,Label 的顶端总是有一条浅浅 ...
- 赛肯德 | 2017NEERC某题
我们枚举每一条边的流量x,将它作为底流(也就是比它大的的流量变成差值,比它小的流量为0),然后我们设x就是路径上第K大的那个边的流量.然后跑最短路,加上dis[n]就是当前的答案.然后取min即可. ...
- java学习笔记—JDBC1(16)
1.数据持久化 l 持久化(persistence):把数据保存到可掉电式存储设备中以供之后使用,也称为“固化”.在大多数情况下,服务器或客户端应用中数据的持久化是通过关系型数据库来实现 l 存储 ...
- 64位虚拟机中安装CentOS_6.7
虚拟机VirtualBox-4.3.24-98716-Win.1425444683.exe,操作系统选用CentOS-6.7-x86_64-LiveDVD .iso. 1) 启动VirtualBox, ...
- mxonline实战14,全局搜索,修改个人中心页面个人资料信息
对应github地址:第14天 一. 全局搜索 1. 使用关键词搜索 courses/views.py/CourseListView新增代码,不用把search_keywords传到前端
- Spring 并发事务的探究
前言 在目前的软件架构中,不仅存在单独的数据库操作(一条SQL以内,还存在逻辑性的一组操作.而互联网软件系统最少不了的就是对共享资源的操作.比如热闹的集市,抢购的人群对同见商品的抢购由一位售货员来处理 ...
- python------对于面向对象的理解
python中一切皆为对象 其实面向对象没什么高大上的东西,只不过把我们平时对于事物的描述和动作系统的总结成了一个定义事物的方法而已. 我们平时向别人介绍一个他(她)从未见过的东西,会从外形和外貌特征 ...