Skip to content

Instantly share code, notes, and snippets.

@htoann
Created June 13, 2022 09:36
Show Gist options
  • Save htoann/9b2ffd8baa553c20e8378370e1e3c4f0 to your computer and use it in GitHub Desktop.
Save htoann/9b2ffd8baa553c20e8378370e1e3c4f0 to your computer and use it in GitHub Desktop.
Trực Thăng
#include<bits/stdc++.h>
using namespace std;
int * kq, * chon, * v; // các m?ng
int n, dem = 0;
void khoitao() {
n = 8;
v = new int[n];
v[0] = 5;
v[1] = 4;
v[2] = 2;
v[3] = 7;
v[4] = 6;
v[5] = 2;
v[6] = 3;
v[7] = 9;
chon = new int[n];
kq = new int[n];
for (int j = 0; j < n; j++) chon[j] = kq[j] = 0;
}
void inkq() {
cout << "\n Cach thu " << ++dem << " :";
for (int j = 0; j < n; j++) cout << " " << kq[j];
}
void tim(int i, int d) {
if (i > n) inkq(); // n?u dã d? h?t n bình xang thì in kq
else
for (int j = 0; j < n; j++) // duy?t h?t các bình xang
{
if (chon[j] == 0 && v[j] > d)
// n?u bình xang chua du?c ch?n và có th? bay hon kho?ng cách d
{
kq[i - 1] = v[j];
chon[j] = 1; // l?y bình xang và dánh d?u dã l?y
tim(i + 1, v[j] - d);
kq[i - 1] = 0;
chon[j] = 0;
}
}
}
int main() {
int d = 2;
khoitao();
tim(1, d);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment