eile
BAN USER
// C#, O(NumOfDice * NumOfDice * Total)
<code><pre class="language-java">
public static string GetMutation(int[] arr, int total)
{
var sum = 0;
var str = "";
foreach (var n in arr)
{
str = str + ", " + n;
sum += n;
}
if (total == sum)
{
return str;
}
return "";
}
public static List<string> GetMutations(int NumOfFace, int NumOfDice, int Sum)
{
var permuation = new List<string>();
//no permuation
if (Sum < NumOfDice || Sum > NumOfFace*NumOfDice)
{
return permuation;
}
var getMin = Sum > NumOfFace? NumOfFace: (Sum-NumOfDice+1) ;
// var dir = new Dictionary<int, int>();
var list = new int[NumOfDice];
for (int j = 0; NumOfDice > j; j++)
{
list[j] = 1;
}
var aaa = GetMutation(list, Sum);
if (!string.IsNullOrEmpty(aaa) )
{
permuation.Add(aaa);
return permuation;
}
bool isoverFlow = false;
while (!isoverFlow)
{
aaa = GetMutation(list, Sum);
if (!string.IsNullOrEmpty(aaa))
{
permuation.Add(aaa);
}
for (int j = 0; j < NumOfDice; j++)
{
if (list[j] == getMin )
{
if (j + 1 == NumOfDice)
{
isoverFlow = true;
break;
}
list[j] = 1;
}
else
{
list[j]++;
for (int k = 0; k < j; k++)
{
list[k] = list[j];
}
break;
}
}
}
return permuation;
}
</code> </pre>
Repjoyjerraj, Android test engineer at ASAPInfosystemsPvtLtd
I am a sales manager .I'm responsible for leading and coaching a team of salespeople. A sales manager's ...
Reptanyaarriol911, Applications Developer at ABC TECH SUPPORT
I am working as a Data entry Manager and I love my job. Also I love to read new Articles ...
Repannawellson007, Area Sales Manager at 8x8
Hey my name is anna And i am working as a content writer in Search engine optimization company.My component ...
RepI graduated from College with a master’s degree in arthrogryposis. After graduation I am working as a manager in ...
Repshirleyjbarker439, Animator at ASAPInfosystemsPvtLtd
Hello, I am Gladys. I am a Industrial Photographer. I started off my photographic career as a News photographer based ...
Repthelmasaraht, Applications Developer at Accolite software
A child protection social worker is responsible for a variety of services designed to help families and children in a ...
Repangilafinch, Applications Developer at Aristocrat Gaming
I am Angila, expert system operator in Linens'n from 2017, Where I interact with network providers and perform troubleshooting ...
Repaaronlustera, Android test engineer at Absolute Softech Ltd
My job is to help groups of people work together better, understand their common goals, and plan to achieve those ...
Repjeniakant, Android test engineer at AMD
Hey I am working as a actor in Film industry from last 10 years.I start My last carrier after ...
Repcherylbgrant, Python Experienced at Bankbazaar
Je suis Cheryl, une traductrice multilingue passionnée avec 3 ans d'expérience dans la traduction de différentes langues telles que ...
Repstephiegoblin, Research Scientist at Aristocrat Gaming
Je suis Stephie, une rédactrice associée très créative, organisée et expérimentée, à la recherche d'un poste de direction dans ...
Repnnatashanaomi, Android test engineer at 247quickbookshelp
I am Marketing managers who play a crucial role in helping a business to promote and its customers. I manage ...
so many bug on that one.
- eile March 14, 2016try to test those.
AAAACCCCBB, ACBACBACBA, ABCCC