The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
Please translate the attached code from C++ to C
Input/Output test cases
Input
The first line contains a single integer RR, with 2≤R≤102≤R≤10, that indicates the number of routines in the recital. Following that will be RR additional lines, each describing the dancers for one routine in the form of a nonempty string of up to 26 non-repeating, lexicographically sorted uppercase alphabetic characters identifying the dancers who perform in that routine. Although a dancer’s letter will not appear more than once in a single routine, that dancer may appear in many different routines, and it may be that two or more routines have the identical set of dancers.
Output
Output a single integer designating the minimum number of quick changes required for the recital.
5
ABC
ABEF
DEF
ABCDE
FGH
|
2
|
6
BDE
FGH
DEF
ABC
BDE
ABEF
|
3
|
4
XYZ
XYZ
ABYZ
Z
|
4 |
Â
// MCPC 2015: Dance Recital// Author: Michael Goldwasser#include <iostream>#include <set>#include <algorithm>using namespace std;#define MAX_R 10int cost[MAX_R][MAX_R];string team[MAX_R];int perm[MAX_R];int main() {int R;cin >> R;for (int j=0; j<R; j++) {cin >> team[j];perm[j] = j;}// calculate all-pairs costsfor (int a=0; a < R; a++)for (int b=0; b < a; b++) {string combined = team[a]+team[b];int overlap = combined.size() - set<char>(combined.begin(),combined.end()).size();cost[a][b] = cost[b][a] = overlap;}// determine best permutationint best = 27*R;do {int count=0;for (int j=0; j < R-1; j++)count += cost[perm[j]][perm[j+1]];best = min(best,count);} while (next_permutation(perm,perm+R));cout << best << endl;}