Kelvin the Frog likes numbers whose digits strictly decrease, but numbers that violate this condition in at most one place are good enough. In other words, if denotes the th digit, then for at most one value of . For example, Kelvin likes the numbers 43210, 132, and 3, but not the numbers 1337 and 123. How many 5-digit numbers does Kelvin like?
Solution
Suppose first that no digit violates the constraint; i.e. the digits are in strictly decreasing order. There are ways to choose the digits of the number, and each set of digits can be arranged in exactly one way, so there are such numbers. We now perform casework on which digit violates the constraint. If it is the final digit, the first four digits must be arranged in decreasing order, which there are ways to do. The final digit can then be any digit, but we have overcounted the ones in which the number is in fully decreasing order (this can happen, for example, if the first 4 digits we chose were , and 2 - a last digit of 1 was already counted in the first case). Therefore, there are new numbers in this case. If the offending digit is second from the right, the first 3 digits must be decreasing, as must the last 2 digits. There are ways to do this. As before, we overcount the case where the second digit from the right is not actually an offender, so we again overcount the case where all 5 digits decrease. Hence there are new numbers in this case. The case where the third digit is the offender is identical to the previous case, so there are another numbers to account for. The final case is when the second digit is the offending digit, in which case there are ways to choose the final 4 digits, but only 9 ways to choose the opening digit (as 0 cannot be a leading digit). Accounting for the usual overcounting, our final answer is which is easily calculated as 14034.