Connection Status:
Competition Arena > FactoryCounting
TCCC06 Round 1B · 2006-08-22 · by Cosmin.ro · Brute Force, Simple Search, Iteration
Class Name: FactoryCounting
Return Type: long
Method Name: count
Arg Types: (int, int, vector<string>)
Problem Statement

Problem Statement

The ACME company is building a factory complex in your county which has k cities. The factory complex is split into n part-building factories and m part-assembling factories. Each factory must be built in a different city of your county because of polution regulations, and there must be a direct road between each building factory and each assembling factory.

You will be given a String[] county. Character j of element i of county will be 'Y' if there is a direct road between city i and city j, and 'N' if there isn't. All roads are bidirectional. Return the number of ways the factory complex can be built in this county. Two factory complexes are different if the set of cities containing part-building factories is different in one than the other, or the set of cities containing part-assembling factories is different in one than the other

Constraints

  • n and m will each be between 1 and 8, inclusive.
  • county will have between 1 and 30 elements, inclusive.
  • Each element of county will have exactly k characters, where k is the number of elements in county.
  • Each character in each element of county will be either 'Y' or 'N'.
  • Character i of element i will always be 'N'.
  • For all i and j, where i != j, character i of element j of county will be equal to character j of element i.
Examples
0)
2
1
{
 "NYY",
 "YNY",
 "YYN"}
Returns: 3

Here we have the following possibilities: part-building factories: {1, 2} part-assembling factories: {3} part-building factories: {1, 3} part-assembling factories: {2} part-building factories: {2, 3} part-assembling factories: {1}

1)
2
2
{
 "NYYYYN",
 "YNYYNY",
 "YYNYYY",
 "YYYNYN",
 "YNYYNY",
 "NYYNYN"}
Returns: 32
2)
1
1
{
 "NNNNYN",
 "NNNYNN",
 "NNNNYN",
 "NYNNYN",
 "YNYYNN",
 "NNNNNN"}
Returns: 8

There are a total of 4 direct roads. For each direct road connecting cities a and b, we have two options: we can either put a part-building factory in city a and a part-assembling factory in city b, or vice versa. Therefore, we have a total 8 possible factory complexes.

3)
3
3
{
 "NYYYNYYNYY",
 "YNYYYYYYYN",
 "YYNYYYNYYN",
 "YYYNYYNYNY",
 "NYYYNYYYYY",
 "YYYYYNYYNY",
 "YYNNYYNYYN",
 "NYYYYYYNNY",
 "YYYNYNYNNY",
 "YNNYYYNYYN"}
Returns: 308
4)
7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}
Returns: 522891760

Submissions are judged against all 85 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class FactoryCounting with a public method long long count(int n, int m, vector<string> county) · 85 test cases · 2 s / 256 MB per case

Submitting as anonymous