next_permutation的使用
来源:互联网 发布:动画模型制作软件 编辑:程序博客网 时间:2024/05/21 06:11
http://www.cplusplus.com/reference/algorithm/next_permutation/?kw=next_permutation
在暴力的时候用这个函数可以使得代码看起来简洁很多。
例如 : LightOJ 1023 - Discovering Permutations
CODE :
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int a[1005];void solve(int n, int k) { for (int i = 0; i < n; i++) a[i] = i; int cnt = 0; do { for (int i = 0; i < n; i++)printf("%c", a[i] + 'A'); printf("\n"); if (++cnt == k)break; }while (next_permutation(a, a + n));}int main() { int T, n, k; scanf("%d", &T); for (int cas = 1; cas <= T; cas++) { scanf("%d%d", &n, &k); printf("Case %d:\n", cas); solve(n, k); } return 0;}
很重要的一点就是不容易写错。
另外相对的还有prev_permutation函数。
0 0
- next_permutation 的使用
- next_permutation的使用
- 使用stl的next_permutation
- next_permutation的使用
- next_permutation函数的使用
- next_permutation 的使用
- next_permutation的原理和使用
- c++ next_permutation()函数的使用
- POJ1146初学使用偷懒的next_permutation()
- 【STL】next_permutation的原理和使用
- 排列函数 prev_permutation和next_permutation的使用
- hdu1716 STL next_permutation函数的使用
- 【转】【STL】next_permutation的原理和使用
- 【STL】next_permutation的原理和使用
- STL算法:prev_permutation和next_permutation的使用
- 【STL】next_permutation的原理和使用
- STL算法:prev_permutation和next_permutation的使用
- hdu 1027 hdu 1716 (next_permutation的使用)
- ecos的中断ISR是怎么与硬件中断向量联系起来的,是怎么被调用的?
- JAVA的反射机制
- 安卓学习总结(二)
- pom
- MDK5.00中*** error 65: access violation at 0x40021000 : no 'read' permission的一种解决方法
- next_permutation的使用
- 一个较完整的SpringMVC工程的配置
- [Splay伸展树]splay树入门级教程
- “三的哲学”——中国人为什么喜欢“三”?
- 自己做地图
- KM P算法 C++版本
- HDU 2059 龟兔赛跑 (动态规划分析)
- Cookie&Session
- 关于selenium的一些书籍和资料