Osm dam, prozatím osm věží

#include <iostream>
using namespace std;
 
const int N = 8;
 
int a [N+1];
 
int cnt = 0;
 
void tisk ()
{
    for (int i = 1; i <= N; i++)
    {
        cout << a [i];
    }
    cout << endl;
}
 
void umisti (int k)
{
    for (int i = 1; i <= N; i++)
    {
        bool ok = true;
        for (int t = 1; t <= k; t++)
            if (a [t] == i)
                ok = false;
 
        if (ok)
        {
            a [k] = i;
            if (k == N)
            {
                tisk (); 
                cnt++;
            }
            else
            {
                umisti (k+1);
            }
        }
    }
}
 
int main()
{
    for (int k = 0; k <= N; k++) 
        a [k] = 0; // take nultou polozku vynulujeme
 
    cnt = 0;
    umisti (1);
    cout << "cnt = " << cnt << endl;
}
 
zalg/dama_ct.txt · Last modified: 2021/03/17 15:11 by 88.103.111.44
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki