Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- ///x- megoldasok tombje
- ///k- rekurzio aktualis lepcsofoka
- /// p- hany elemu reszhalmazok(szamok lesznek)
- ///counter- counter :)))))))
- ///n-hatar
- bool igeretes(int x[],int k) {
- for(int i=0; i<k; i++){
- if (x[k] <= x[i]) {///ellenorizzuk a novekvo sorrendet "kigeneralt" reszhalmazokban
- return false;
- }
- }
- return true;
- }
- int kiir(int x[],int k){
- for(int i=0; i<=k; i++){
- cout << x[i] << " ";
- }
- cout << "\n";
- }
- void backTracking(int x[], int k,int p, int &counter, int n) {
- for (int i = 1; i <= n; ++i) {
- x[k] = i;
- if (igeretes(x, k)) {
- if (k == p - 1) {
- counter++;
- kiir(x, k);
- } else {
- backTracking(x, k + 1, p, counter, n);
- }
- }
- }
- }
- int main() {
- int p = 4;
- int x[p];
- int counter=0;
- int n=6;
- backTracking(x, 0, p, counter, n);
- cout<<"\n"<< counter;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement