473,387 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

I need some help with a backtracking problem."I am a noob)"

1
Problem:

There are 15 hunters in one locality. Teams of 3 people are formed between them, so that in

during the 7 days of the hunt, no participant should be with any of those with

who has been on the team before. Determine the composition of the teams for the 7 days.

Can someone give me an idea of ​​how I could solve it?
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. int n, p, v[20];
  3. using namespace std;
  4.  
  5. int valid(int k)
  6.     {
  7.         if (k == p) return 1;
  8.         return 0;
  9.     }
  10.  
  11. void show(int k)
  12.     {
  13.         for (int i = 1; i <= k; i++) cout << v[i] << " ";
  14.         cout << endl;
  15.     }
  16.  
  17. void BK(int k)
  18.     {
  19.         for (int i = v[k - 1] + 1; i <= n; i++)
  20.         {
  21.             v[k] = i;
  22.             if (valid(k))
  23.                 show(k);
  24.             else
  25.                 BK(k + 1);
  26.         }
  27.     }
  28.  
  29. int main()
  30.     {
  31.         cout << "n= "; cin >> n; cout << "p= "; cin >> p;
  32.         BK(1);
  33.         return 0;
  34.     }
  35.  
Nov 25 '21 #1
0 3238

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: frank | last post by:
Below is some code for doing and insert into one of my tables. The inserts do not work because a duplicate key exists, which I want to happen. The problem is, I cannot get access to return an error...
7
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte...
1
by: swtstrawberry | last post by:
This program is supposed to present the buyer with an inventory list and ask if they would like to make a purchase, then enter the item number for purchase, then the amount of that item they would...
18
by: Scott | last post by:
Hi, a problem with this following code is really bugging me. tform = fopen(country, "r"); fseek(tform, 9L, SEEK_SET); fgets(player2, 38, tform); printf("Player Name (save): %s", player);...
1
by: Dave Siegel | last post by:
Hi. I know what im doing wrong but i dont know how to fix it. I have the follow code Private Sub Command1_Click() If Text2.Text = App.Path & "\members\" & Text1.Text & "\password.txt"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.