Hello everyone, I have a question. How can you tell how many different permutations a string has if it has even repeated elements?
The size of the chain is up to 100 dnd I think calculating the factorial would commonly be very long.
Hello everyone, I have a question. How can you tell how many different permutations a string has if it has even repeated elements?
The size of the chain is up to 100 dnd I think calculating the factorial would commonly be very long.
# | User | Rating |
---|---|---|
1 | tourist | 3690 |
2 | jiangly | 3647 |
3 | Benq | 3581 |
4 | orzdevinwang | 3570 |
5 | Geothermal | 3569 |
5 | cnnfls_csy | 3569 |
7 | Radewoosh | 3509 |
8 | ecnerwala | 3486 |
9 | jqdai0815 | 3474 |
10 | gyh20 | 3447 |
# | User | Contrib. |
---|---|---|
1 | maomao90 | 173 |
2 | awoo | 164 |
3 | adamant | 163 |
4 | TheScrasse | 160 |
5 | nor | 157 |
6 | maroonrk | 156 |
7 | -is-this-fft- | 152 |
8 | Petr | 146 |
8 | orz | 146 |
10 | pajenegod | 145 |
Name |
---|
The number of permutations of n elements, where there are a1 copies of the first element, a2 copies of the second element, a3 copies of the third element and so on (so a1 + a2 + a3 + ... + ak = n) is:
You can preprocess all factorials up to 100, and compute the above formula.
Most likely, it will overflow even a 64-bit integer, so either you can use BigInteger for it, or I'm assuming that the problem asks for it modulo some prime (e.g. 109 + 7). In the latter case, you can use modular inverses to divide.