next_permutation(排列问题)
来源:互联网 发布:仓库数据流程图 编辑:程序博客网 时间:2024/05/22 14:32
全排列的模板
#include <iostream> // std::cout
#include <algorithm> // std::next_permutation, std::sortint main () {
int myints[] = {1, 2, 3};
std::sort(myints, myints + 3);
std::cout << "The 3! possible permutations with 3 elements:\n";
do {
std::cout << myints[0] << ' ' << myints[1] << ' ' << myints[2] << '\n';
} while ( std::next_permutation(myints, myints + 3) );
std::cout << "After loop: " << myints[0] << ' ' << myints[1] << ' ' << myints[2] << '\n';
return 0;
}
计算n个数的第k个排列
#include <bits/stdc++.h>using namespace std;int main(){ int a[1010]; int n,k; cin>>n>>k; for(int i=0;i<n;i++) a[i]=i+1; sort(a,a+n); int i=0; while(next_permutation(a,a+n)){ i++; if(i==k-1) break; } for(int i=0;i<n-1;i++) cout<<a[i]<<" "; cout<<a[n-1]<<endl; return 0;}
阅读全文
0 0
- next_permutation(排列问题)
- 全排列(next_permutation)
- next_permutation(全排列)
- 全排列问题的STL用法(next_permutation类)
- 全排列问题的STL用法(next_permutation类)
- (转载)全排列next_permutation
- 全排列函数 next_permutation()
- POJ 1833 排列(next_permutation)
- next_permutation函数(全排列)
- next_permutation函数(全排列)
- 全排列(next_permutation,递归)
- 排列(next_permutation)
- next_permutation在排列类问题中的应用
- next_permutation解决排列问题的利器
- STL中用next_permutation解决排列问题
- 排列问题算法-next_permutation,康托编码
- 求全排列函数 (next_permutation())
- POJ1833 排列(next_permutation()的应用)
- 计算机基础知识
- WUST OJ 1552: Stock
- Spring in Action 第二章
- STM32学习笔记之-串口中断接收不定数据buff
- RecyclerView使用完全指南
- next_permutation(排列问题)
- 数据仓库--数据建模(未完)
- JDBC总结
- IBM Ponder This November 2009【贪心】【哈夫曼树】
- jQuery自带的一些常用方法总结
- ZooKeeper 学习 (三) 客户端zkCli.sh以及相关操作命令
- 《编程之美》寻找发帖水王 质疑
- ORACLE学习之PL/SQL中异常
- 为解决的错误