Home > Net >  Algorithm for a number of M, N, N> M
Algorithm for a number of M, N, N> M

Time:05-01

Algorithm for a number of M, N, N> M
Such as Numbers, 1, 2, 3, 4,
The results are as follows:
1 1 1 1
1 1 1 2
1 1 1 3
1 1 2 2
1 1 2 3
1 1 3 3
1 2 2 2
1 2 3 2
1 2 3 3
3 3 3 1
2 2 2 2
2 2 2, 3,
2, 2, 3, 3
2, 3, 3 3
3 3 3 3
That can be repeated, no order can be arbitrary,

CodePudding user response:

This fee head seem reluctant to think

CodePudding user response:

Yeah, don't want to waste brain,

Change your topic to, we see at a glance, you can do

12 take 3, you feel?? A clock dial, only a three pointer, 12 hours, turn a lap down, about the whole arrangement, will not repeat

So, according to the clock so write well, one revolution of the second hand, minute hand into one, one revolution of the minute hand and hour hand into a

Namely N into the system

CodePudding user response:

Two loops to solve

CodePudding user response:

O (n ^ m) recursion, n=3, m=4, 81,
Not recursive directly write cycle 4 layer,

CodePudding user response:

So, if you still can't see, let's change the more straightforward
0,1,2,3,4,5,6,7,9
Take three

Does
000
001
002
003
-- -- -- -- --

009
010
-- -- -- -- -- --

999

He all not, repeat not

As for what N> M, in fact is a smoke screen, don't worth considering

N> The M is? Also is to use N as the base, not M as the base, how do you carry on how to carry, but when was the last show take a remainder (die), that is, the value of the current % M


CodePudding user response:

Oh, really is a distraction, I also lost, but the conclusion is correct, is not worth considering
Above is fan, repair, or M hexadecimal

Who says decimal number cannot express 11 data, so don't consider "N" at M, this condition is used to confuse people

CodePudding user response:

reference flying phoenix 601 reply: 3/f
two loops to solve things


The
reference 4 floor guanyinsishengzi reply:
O (n ^ m) recursion, n=3, m=4, number 81,
Not recursive directly write cycle, 4 layer


Fairy fight, ha ha, to the end of several cycles

CodePudding user response:

refer to 6th floor wanghui0380 response:
oh, is indeed a smoke screen, I also lost, but the conclusion is correct, is not worth considering
Above is fan, repair, or M hexadecimal

Who says decimal number cannot express 11 data, so don't consider "N" at M, this condition is used to confuse people

Thank you for your reply,

CodePudding user response:

refer to 6th floor wanghui0380 response:
oh, is indeed a smoke screen, I also lost, but the conclusion is correct, is not worth considering
Above is fan, repair, or M hexadecimal

Who says decimal number cannot express 11 data, so don't consider "N" at M, this condition is used to confuse people


M> N, or M CodePudding user response:

Arrange for M number, N, N> M
N> M is the chance of errors because the condition does not meet the conditions of
Writing number M, N, M> N
You can first combination, in the result of the combination of order
There are many permutations and combinations of code, is the permanent topic programmer, because efficiency is always the first

CodePudding user response:

references 9 f marmothac response:
Quote: refer to the sixth floor wanghui0380 response:
oh, is indeed a smoke screen, I also lost, but the conclusion is correct, is not worth considering
Above is fan, repair, or M hexadecimal

Who says decimal number cannot express 11 data, so don't consider "N" at M, this condition is used to confuse people


M> N, or M

Didn't you think so complicated, you know, he is to carry literally write, anyway to have a holiday, no mood to write code, I wrote them with a, what also don't pay attention to efficiency, performance, optimum, you see, the so-called N, M size for you to realize if there is any difference, anyway, for me the following code, there is no difference between

 test test=new test (3, 4); 
Dic int []=new int [] {1, 2, 3};

Do
{
Console. WriteLine (string. Join (", ", the test GetCcurentIndex (). The Reverse (), Select (p=& gt; Dic [p])));

} while (test. The Increment ());


Public class test
{
Private readonly int _m;
Private readonly int _n;

Private node nodel;
The public test (int M, int N)
{
_m=M;
_n=N;
Nodel=new node (M);

The node ccurentnode=nodel;
for (int i=0; I & lt; _n - 1; I++)
{
The node tempnode=new node (M);
Ccurentnode. Parent=tempnode;
Ccurentnode=tempnode;
}
}

Public bool Increment ()
{
Var LST=GetCcurentIndex ();
if (! LST. All (p=& gt; P==_m - 1))
{
Nodel. Increment ();



return true;
}
The else
{
return false;
}

}
Public IEnumerable GetCcurentIndex ()
{
Return the Show (nodel);
}

Private IEnumerable Show (node node)
{
Yield return node. The Value;
If (node parent!=null)
{
Var temp=Show (node. The parent);
The foreach (var item in temp)
{
Yield return item;
}
}
The else
{
Yield break;
}

}

//a node
Public class node
{
Private readonly int _n;

Public int Value {get; set; }=0;
Public node parent {get; set; }

Public node (int N)
{

_n=N;
}

//simulation + 1, decide whether to carry
Public void Increment ()
{
Value=https://bbs.csdn.net/topics/Value + 1;
If (Value=https://bbs.csdn.net/topics/=_n)
{

The parent? The Increment ();

}

Value=https://bbs.csdn.net/topics/Value % _n;
}
}


}


The results

1,1,1,1
Say
1,1,1,3
1,1,2,1
1,1,2,2
1,1,2,3
1,1,3,1
1,1,3,2
1,1,3,3
1,2,1,1
1,2,1,2
1,2,1,3
1,2,2,1
1,2,2,2
1,2,2,3
1,2,3,1
1,2,3,2
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • C#