Goose Tattarrattat has a machine that contains N gears (cogwheels).
The gears are numbered 0 through N-1.
Each of the gears has one of three colors: red, green, or blue.
Some pairs of gears mesh.
Let X and Y be two meshing gears.
Note that if X is turning, Y must clearly be turning in the opposite direction (clockwise vs. counter-clockwise).
Two gears with the same color never mesh.
Apart from that, do not assume anything about the pairs of meshing gears.
You are given a String color and a String graph.
For each i, character i of color represents the color of gear i: 'R' is red, 'G' is green, and 'B' is blue.
The String graph contains the information on meshing pairs of gears:
If the j-th character of the i-th element of graph is 'Y', gear i meshes with gear j.
We want all gears to turn at the same time.
Additionally, all gears of the same color must turn in the same direction.
Return the minimal number of gears that have to be removed from the machine in order to achieve this goal.
|Method signature:||int getmin(String color, String graph)|
|(be sure your method is public)|
|-||Removing a gear creates a gap between the other gears, no new meshing pairs of gears are created by removing a gear.|
|-||The graph described by graph is not necessarily planar.|
|-||color will contain between 2 and 50 characters, inclusive.|
|-||Each character in color will be 'R' or 'G' or 'B'.|
|-||graph will contain exactly N elements, where N is the number of characters in color.|
|-||Each element of graph will contain exactly N characters, where N is the number of characters in color.|
|-||Each character in graph will be either 'Y' or 'N'.|
|-||For each i, the i-th character of the i-th element of graph will be 'N'.|
|-||For each i and j, the i-th character of the j-th element of graph and the j-th character of the i-th element of graph will be same.|
|-||For each i and j, if the i-th and the j-th character of color are equal, then the i-th character of the j-th element of graph will be 'N'.|
|We have three gears, each meshes with each of the others.
In this configuration the gears are not able to turn at all.
However, as soon as we remove any of the gears, the other two will be able to turn.|
|Here, each of the gears can turn without interacting with the others.|
|These are four gears arranged into a row. It is possible to turn all these gears at the same time, but the two red gears would turn in opposite directions. Thus we need to remove at least one gear.|
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.