CyclesNumber
Find all \ (n-\) Rotation number of substitutions points \ (m \) times and ⽅.
\ (T \ leq 300, n \ leq 10 ^ 5, m \ leq 300 \) .
answer
https://www.cnblogs.com/jefflyy/p/9425348.html
Pre-knowledge
According to "specific math" Sterling has several properties:
\[ \begin{Bmatrix}n+1\\m+1\end{Bmatrix}=\sum_{k=m}^n\binom{n}{k}\begin{Bmatrix}k\\m\end{Bmatrix}\\ \begin{bmatrix}n+1\\m+1\end{bmatrix}=\sum_{k=m}^n\binom{n}{k}\begin{bmatrix}k\\m\end{bmatrix}(n-k)!=n!\sum_{k=m}^n\frac{\begin{bmatrix}k\\m\end{bmatrix}}{k!}\\ \]
Meaning the combination of these two formulas it is clear, and it should be proved by induction.
There is also a similar formula:
\[ \begin{bmatrix}n+1\\m+1\end{bmatrix}=\sum_{k=m}^n\begin{bmatrix}n\\k\end{bmatrix}\binom{k}{m} \]
But it does not sense any combination, try to prove it by induction.
\[ \begin{bmatrix}n+1\\m+1\end{bmatrix}=\begin{bmatrix}n\\m\end{bmatrix}+n\begin{bmatrix}n\\m+1\end{bmatrix}\\ \begin{bmatrix}n\\m\end{bmatrix}=\sum_{k=m-1}^{n-1}\begin{bmatrix}n-1\\k\end{bmatrix}\binom{k}{m-1}\\ n\begin{bmatrix}n\\m+1\end{bmatrix}=n\sum_{k=m}^{n-1}\begin{bmatrix}n-1\\k\end{bmatrix}\binom{k}{m}\\ \]
The second dimension noticed several different combinations, so the first task is to put together a combination of numbers.
\[ \begin{bmatrix}n\\m\end{bmatrix}=\sum_{k=m}^{n}\begin{bmatrix}n-1\\k-1\end{bmatrix}\binom{k-1}{m-1}\\ n\begin{bmatrix}n\\m+1\end{bmatrix}=\sum_{k=m+1}^{n}\begin{bmatrix}n-1\\k-1\end{bmatrix}\binom{k-1}{m}+(n-1)\sum_{k=m}^{n-1}\begin{bmatrix}n-1\\k\end{bmatrix}\binom{k}{m}\\ \begin{bmatrix}n\\m\end{bmatrix}+n\begin{bmatrix}n\\m+1\end{bmatrix}=\sum_{k=m}^n\begin{bmatrix}n-1\\k-1\end{bmatrix}\left(\binom{k-1}{m-1}+\binom{k-1}{m}\right)+(n-1)\sum_{k=m}^{n-1}\begin{bmatrix}n-1\\k\end{bmatrix}\binom{k}{m}\\ =\sum_{k=m}^n\begin{bmatrix}n-1\\k-1\end{bmatrix}\binom{k}{m}+(n-1)\sum_{k=m}^{n-1}\begin{bmatrix}n-1\\k\end{bmatrix}\binom{k}{m}\\ =\sum_{k=m}^n\left(\begin{bmatrix}n-1\\k-1\end{bmatrix}+(n-1)\begin{bmatrix}n-1\\k\end{bmatrix}\right)\binom{k}{m}=\sum_{k=m}^n\begin{bmatrix}n\\k\end{bmatrix}\binom{k}{m} \]
Sterling routine
这道题求的是:
\[ ans=\sum_{i=1}^n\begin{bmatrix}n\\i\end{bmatrix}i^m\\ =\sum_{i=1}^n\begin{bmatrix}n\\i\end{bmatrix}\sum_{j=0}^m\begin{Bmatrix}m\\j\end{Bmatrix}j!\binom{i}{j}\\ =\sum_{j=0}^m\begin{Bmatrix}m\\j\end{Bmatrix}j!\sum_{i=1}^n\begin{bmatrix}n\\i\end{bmatrix}\binom{i}{j}\\ =\sum_{j=0}^m\begin{Bmatrix}m\\j\end{Bmatrix}j!\begin{bmatrix}n+1\\j+1\end{bmatrix} \]
\ (O (nm) \) pretreatment number of a first type Stirling, \ (O (m ^ 2) \) pretreated Stirling numbers of second kind, can be \ (O (m) \) to answer a asked
Topcoder evaluation machine is rubbish, I feel at random to score. After a difference of only two one-line comment submitted you can get different points.
To AC This question must be put to a pre-factorial \ (the n-\) , I do not know why.
int S1[100010][310],S2[310][310],fac[100010];
void init(int n,int m){
S1[0][0]=1;
for(int i=1;i<=n+1;++i)for(int j=1;j<=min(i,m+1);++j)
S1[i][j]=add(S1[i-1][j-1],mul(i-1,S1[i-1][j]));
S2[0][0]=1;
for(int i=1;i<=m;++i)for(int j=1;j<=i;++j)
S2[i][j]=add(S2[i-1][j-1],mul(j,S2[i-1][j]));
fac[0]=1;
for(int i=1;i<=n;++i) fac[i]=mul(fac[i-1],i);
}
int solve(int n,int m){
if(m==0) return fac[n];
int ans=0;
for(int i=0;i<=m;++i) ans=add(ans,mul(S2[m][i],mul(fac[i],S1[n+1][i+1])));
return ans;
}
class CyclesNumber{
public:
vector<int> getExpectation(vector<int> n,vector<int> m){
init(1e5,300);
vector<int> ans(n.size());
for(int i=0;i<(int)n.size();++i) ans[i]=solve(n[i],m[i]);
return ans;
}
};