Solutions for Skillrack CSE1002 Inlab 3

Total time : 20 mins

Challenges : 1

Question (Guiding a Travelling Salesman)

A laptop sales company wants their salesperson to visit some cities every month and promote their sales.  A code has to be written to find the sequence of visit so that he travels the minimum. Given ‘n’ cities and a home city, design an algorithm and write a C++ code to determine the number of routes to be evaluated when the problem is to be solved by brute force approach. For example, if there are four cities A, B, C, and D and ‘A’ is the home city then brute force method calculate distance of the following routes:
A B C D A
A B D C A
A C B D A
A C D B A
A B C D A
A B D C A
By default the company assign only five months every month for each of its employee but it may vary.
Input Format
Number of cities
Name of the cities
Home city name
Output Format
Number of routes to be analyzed in brute force approach

Solution

#include< iostream >
using namespace std;
int fact(int n)
{
 int f=1;
 for(int i=n;i > 1;i--)
 f*=i;
 return(f);
}
int main()
{
 int n;
 char ch;
 cin>>n;
 for(int i=0;i < n;i++)  
 cin>>ch;
 cin>>ch;
 cout<<fact(n-1);
 return(0);
}

Input

INPUT :

4
A
B
C
D
A

Output

OUTPUT :

6
Share on Google Plus

About Unknown

This blog is exclusively for VITIAN'S TO fulfill their needs. Also you can tell our team your need and we will assist you as soon as possible. For any quaries send your emails to "everything4vitians@gmail.com". Thank you
    Blogger Comment

0 comments:

Post a Comment