Is this identity trivial? $n^n=n!+\sum_{k=1}^{n-1}(-1)^{k+1}\binom{n}{k}(n-k)^n$

I'm not sure if this counts as "trivial" (and this is at heart identical to your surjections argument) but just note that you are counting the number of functions $\{1,\dots,n\}\to\{1,\dots,n\}$ in two ways.

The LHS is just $n^n$ because each of $1,\dots,n$ is mapped to one of $n$ possible values.

The RHS is inclusion-exclusion, where your sets $A_i$ are the set of all functions that don't include $i\in\{1,\dots,n\}$ in their image. The number of functions that don't hit (at least) $k\geq1$ points is $\binom {n}{k}(n-k)^n$, as you choose $k$ "illegal" points, and then each of $1,\dots,n$ map to any of the other $n-k$ "legal" points.

The $n!$ term is to account for the number of functions that hit every point, i.e. the permutations.


It is not quite trivial, but your identity $$ n^n=n!+\sum_{k=1}^{n-1}(-1)^{k+1}\binom{n}{k}(n-k)^n $$ can be easily simplified to $$ n!=\sum_{k=0}^n(-1)^k\binom{n}{k}(n-k)^n = \sum_{k=0}^n(-1)^{n-k}\binom{n}{k}k^n $$ which is well known in combinatorics and proved in several ways including inclusion-exclusion. The OEIS sequence A000142 for the factorial sequence has this formula $$ \sum_{i=0}^n (-1)^i(n-i)^n \binom{n}{i} = n!. $$ Also see MSE question 1512743 "An identity for the factorial function".