Permutation algorithm in the form

R= repeats allowed -> 2
A= alphabet (1-10)
S= space = 4;

So we want an example:

[1][1][4][5]
[1][7][4][5]
[5][1][4][5]

But do we need a fantastic mathematical formula to calculate this and all combinations?

+3
source share
6 answers

As I understand it, your alphabet is 1 .. 10, and each "letter" can occur twice. So you really have an alphabet that ...

1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10

It has a length of 20, not 10.

Now the problem translates to 20. 4.

Hope this helps.

EDIT: According to your additional comments on your question, you can check each generated permutation to see if it has the form XXYY, as that would be incorrect according to what you wrote.

+4
source

- <p >   N * [(S 1) * ((N-1) (S-1))       + (S 2) * ((N-1) (S-2))       +...       + (S R) * ((N-1) (S-R))]

  • , , 1 (S choose 1 ) N-1 S-1 ; ( , N permute S)

  • 2 (S choose 2 ) N-1 S-2.

  • .. , 1 R

  • N .

.

. @blueraja, ! n-repeat-items 1 !

(N permute S)
+ N * [ (S choose 2) * ((N-1) permute (S-2)) 
      + (S choose 3) * ((N-1) permute (S-3)) 
      + ... 
      + (S choose R) * ((N-1) permute (S-R)) ]
+3

. , , .

:

  • , . 10 P 4
  • , :
    • , : 10 C 1
    • : 4 C 2
    • , : 9 P 2

, 9360.

+3

(< 10000), ^ 4, .

  • () N
  • ,

  • N-1

  • , .
0

, , .

, A ( ), S ( ) R ( ):

f (A, S, R) = (A perm S) + ASum [r = 2 to R] ((S r) (A-1 perm Sr))

, R = 1 ( ) f (A, S, R) = (A perm S), . A = S = R = 2 f (A, S, R) = 4, :

1,2

2,1

1,1

2,2

, , A = 10, R = 2, S = 4, :

f (A, S, R) = 9360

( , BlueRaja)

0
source

This is a good article on combinations and permutations, there you can find all the formulas

0
source

Source: https://habr.com/ru/post/1745447/


All Articles