Problem 2325. GJam 2014 Rd 1c: Reordering Train Cars (Large)
Determine number of sequences for set of strings under the constraint that all same characters must be contiguous. The large case could have 26! or more permutations.
Input: s, string of N space separated string segments of letters [a..z]. 1<=N<=100. Total letters <=100.
Output: val, number of possible sequences, modulo 1,000,000,007
Example: Small Train Case examples
ab bbbc cd Val=1 as only abbbbccd can be created
aa aa bc c Val=4 aa gives 2 positions, aa'aa''bcc,aa''aa'bcc, bcccaa'aa'',bcccaa''aa'
abc bcd Val=0 as c is internal and thus can not connect to c of abc
Large Case specific info. See Usage of java math for unlimited precision. Note intValue gives more precision than floatValue. No java factorial exists so a function, non-recursive, is suggested. The small solution can be converted via java BigInteger factorial, mod, multiply, and intValue to solve the large case.
Additional GJam solutions can be found at Example GJam Matlab solutions. Select Find Solutions, change Language to Matlab. The Test Suite, at the bottom, contains a full GJam Small Matlab solution. No Valid Matlab solutions were submitted during the contest.
Solution Stats
Problem Comments
-
2 Comments
mmmriva
on 21 May 2014
Can you please check the test suite as test 30 is uncomplete ? Thanks.
Richard Zapor
on 1 Oct 2020
Updated test suite to fix the cropping. 10/1/2020
Solution Comments
Show commentsProblem Recent Solvers2
Suggested Problems
-
27525 Solvers
-
Determine whether a vector is monotonically increasing
20756 Solvers
-
17101 Solvers
-
Find the peak 3n+1 sequence value
2498 Solvers
-
How many monitors are connected ?
152 Solvers
More from this Author308
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!