Advertisement
RaFiN_

factorial number system and finding lex permutation

Jun 9th, 2020
795
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 1.01 KB | None | 0 0
  1. Pemutation to factoradic conversions:
  2. Given a permuation 3,0,2,1. It's factoradic representation is not simply 4132!. We have to put some mind to it.
  3.  
  4. We have n=4. So we have A×3!+B×2!+C×1!+D×0!. We have to find the values of A,B,C and D.
  5.  
  6. A = We can simply do that by finding number of elements smaller than 3. That is 3.
  7. Now we remove 3 from consideration, and have {0,1,2}.
  8. B = Number of elements smaller than 0? None. So 0. Remove 0. We're left with {1,2}.
  9. C = Number of elements smaller than 2? 1. So 1. We have {1} left.
  10. D = 0
  11. So, we have 3010!, representing 3,0,2,1. To double check, you can find the decimal value, which comes out to be: 3×3!+0×2!+1×1!+0×0!=18+0+1+0=19
  12.  
  13. As you can see here, 3021, is indeed the 19th permutation for n=4.
  14.  
  15. The basic inference you can get from here is that factoradic representation gives the rank of the number, for the remaining numbers.
  16.  
  17. This can be done by fenwick trees / Binary indexed trees, easily
  18.  
  19.  
  20.  problem : https://codeforces.com/contest/501/problem/D
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement