惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - Franky
酷 壳 – CoolShell
酷 壳 – CoolShell
Google Online Security Blog
Google Online Security Blog
Engineering at Meta
Engineering at Meta
U
Unit 42
Security Latest
Security Latest
G
Google Developers Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
D
Docker
T
Tailwind CSS Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
云风的 BLOG
云风的 BLOG
Hugging Face - Blog
Hugging Face - Blog
M
MIT News - Artificial intelligence
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
MongoDB | Blog
MongoDB | Blog
H
Help Net Security
Stack Overflow Blog
Stack Overflow Blog
C
Check Point Blog
S
Security Affairs
T
The Exploit Database - CXSecurity.com
S
SegmentFault 最新的问题
N
News and Events Feed by Topic
The GitHub Blog
The GitHub Blog
Apple Machine Learning Research
Apple Machine Learning Research
S
Securelist
IT之家
IT之家
P
Palo Alto Networks Blog
D
DataBreaches.Net
Help Net Security
Help Net Security
N
Netflix TechBlog - Medium
B
Blog RSS Feed
AWS News Blog
AWS News Blog
Scott Helme
Scott Helme
爱范儿
爱范儿
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
腾讯CDC
I
Intezer
J
Java Code Geeks
大猫的无限游戏
大猫的无限游戏
Microsoft Security Blog
Microsoft Security Blog
人人都是产品经理
人人都是产品经理
G
GRAHAM CLULEY
N
News | PayPal Newsroom
博客园 - 三生石上(FineUI控件)
A
Arctic Wolf
F
Fortinet All Blogs
The Register - Security
The Register - Security
Recent Commits to openclaw:main
Recent Commits to openclaw:main
博客园 - 【当耐特】

博客园 - Zero Lee

调用栈(call stack) 关于STL allocator Calculate maximum sum of any subarray set Calcuate power n of x recursively Convert one binary search tree to double-linked list 设计包含min函数的栈 类模板的模板友元函数定义 一道百度的面试题解答 非printf形式的十六进制和二进制打印(雅虎面试题) 一道腾讯面试题 (转)C++中extern “C”含义深层探索 selection algorithm to select nth small elements based on partition 删除与某个字符相邻且相同的字符 产生全排列的方法解析 求一个正整数的平方根程序实现 [转]多线程队列的算法优化 [转载] STL allocator的介绍和一个基于malloc/free的allocator的简单实现 如何将一片内存链接成链表 One simple counted object pointer
一组数的全排列和组合程序实现
Zero Lee · 2012-06-17 · via 博客园 - Zero Lee

显示一组数的全排列和组合程序:

 1 void print(const std::vector<int>& s)
 2 {
 3     static int n = 1;
 4     printf("%d:", n++);
 5     printf("[");
 6     for (int i = 0; i < s.size(); i++)
 7         printf(" %d ", s[i]);
 8     printf("]\n");
 9 }
10 
11 void permutation(std::vector<int>& v, int beg, int end)
12 {
13     if (beg > end) {
14         print(v);
15         return;
16     }
17     for (int i = beg; i <= end; i++) {
18         std::swap(v[i], v[beg]);
19         permutation(v, beg+1, end); // pleate note, here always beg+1, not i+1
20         std::swap(v[i], v[beg]);
21     }
22 }
23 
24 void pm(std::vector<int>& v)
25 {
26     std::copy(v.begin(), v.end(), std::ostream_iterator<int>(std::cout, " "));
27     printf("\nfull permulation are:\n");
28     permutation(v, 0, v.size()-1);
29 }
30 
31 void print(const std::vector<int>& v, int beg, int end)
32 {
33     static int n = 1;
34     printf("%d:", n++);
35     printf("[");
36     std::copy(v.begin()+beg, v.begin()+end+1, std::ostream_iterator<int>(std::cout, " "));
37     printf("]\n");
38 }
39 
40 void fullcombination(std::vector<int>& v)
41 {
42     printf("full combination are:\n");
43     for (unsigned int i = 0; i < v.size(); i++) {
44         print(v, i, i);
45         for (unsigned int j = i+1; j < v.size(); j++) {
46             for (int k = 0; k < v.size()-j; k++) {
47                 std::swap(v[j+k], v[j]);
48                 print(v, i, j);
49                 std::swap(v[j+k], v[j]);
50             }
51         }
52     }
53 }
54