GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — QPAlgorithm/funcC.cpp at master · haiwen007/QPAlgorithm

Expand file tree

/

funcC.cpp

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
164 lines (154 loc) · 3.23 KB
/

funcC.cpp

Copy path

File metadata and controls

164 lines (154 loc) · 3.23 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
//
// Created by [email protected]
// 5/26/2019
//
#include <time.h>
#include <algorithm>
#include "math.h"
#include <iostream>
#include <memory>
#include <utility>
#include <sys/types.h>
#include <sstream>
#include <fstream>
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include "funcC.h"
//求组合C(n,k)
CFuncC::CFuncC() :c(0) {
}
//深度遍历实现找规律
int CFuncC::Depth() {
//深度优先遍历,由浅到深,广度遍历,由里向外
printf("\n------------\n");
int c = 0;
int e[6] = { 0 };
e[0] = 4;
for (int i = 4; i > 0; --i) {
e[1] = i;//深度为1
for (int j = 4; j > 0; --j) {
e[2] = j;//深度为2
for (int k = 4; k > 0; --k) {
e[3] = k;//深度为3
for (int x = 4; x > 0; --x) {
e[4] = x;//深度为4
//for (int y = 4; y > 0; --y) {
// e[5] = y;//深度为5
//for (int z = 4; z > 0; --z) {
//e[6] = z;//深度为6
++c;
for (int m = 1; m <= e[0]; ++m) {
printf("%d", e[m]);
}
printf(" ");
//}
//}
}
}
}
}
printf("\nc = %d\n\n", c);
return c;
}
//求组合C(n,k),返回数组集合
//arr((i0),...) = F(C(n,1))
//arr((i0,i1),...) = F(C(n,2))
//arr((i0,i1,i2),...) = F(C(n,3))
//arr((i0,i1,...ik),...) = F(C(n,k))
int CFuncC::FuncC(int n, int k, std::vector<std::vector<int>>& vec) {
c = 0;
e[0] = k;
vec.clear();
return StaC(n, k, vec);
}
//求组合C(n,1)*C(n,1)...*C(n,1)
//f(k)=C(n,1)
//Muti(k)=f(1)*f(2)...*f(k)
//n int 访问广度
//k int 访问深度
//深度优先遍历,由浅到深,广度遍历,由里向外
int CFuncC::DepthVisit(int n, int k) {
c = 0;
e[0] = k;
return DepthC(n, k);
}
//递归求组合C(n,k)
//n int 访问广度
//k int 访问深度
//深度优先遍历,由浅到深,广度遍历,由里向外
int CFuncC::StaC(int n, int k, std::vector<std::vector<int>>& vec) {
for (int i = n; i >= k; --i) {
assert(k > 0);
e[k] = i;
if (k > 1) {
//递归C(i-1,k-1)
StaC(i - 1, k - 1, vec);
}
else {
++c;
for (int j = e[0]; j > 0; --j) {
//printf("%d", e[j]);
v.push_back(e[j] - 1);
}
//printf(",");
vec.push_back(v);
v.clear();
}
}
//返回组合数
return c;
}
//递归求组合C(n,1)*C(n,1)...*C(n,1)
//f(k)=C(n,1)
//Muti(k)=f(1)*f(2)...*f(k)
//n int 访问广度
//k int 访问深度
//深度优先遍历,由浅到深,广度遍历,由里向外
int CFuncC::DepthC(int n, int k) {
for (int i = n; i > 0; --i) {
assert(k > 0);
e[k] = i;
if (k > 1) {
//递归C(n,k-1)
DepthC(n, k - 1);
}
else {
++c;
for (int j = e[0]; j > 0; --j) {
printf("%d", e[j]);
}
printf(" ");
}
}
//返回组合数
return c;
}
void CFuncC::Print(std::vector<std::vector<int>>& vec) {
for (std::vector<std::vector<int>>::iterator it = vec.begin();
it != vec.end(); ++it) {
for (std::vector<int>::iterator ir = it->begin();
ir != it->end(); ++ir) {
printf("%d", *ir);
}
printf(" ");
}
printf("\n");
}
void CFuncC::Test() {
CFuncC C;
std::vector<std::vector<int>> vec;
while (1) {
int n, k;
std::cin >> n >> k;
int c = C.FuncC(n, k, vec);
printf("\n%d\n", c);
//CFuncC::Print(vec);
}
}
void CFuncC::Test1() {
int c0 = CFuncC::Depth();
CFuncC C;
int c = C.DepthVisit(4, 4);
printf("\nc0=%d c=%d\n\n", c0, c);
}
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.