Project Euler 743
Project Euler 743
题目
Window into a Matrix
A window into a matrix is a contiguous sub matrix.
Consider a $2\times n$ matrix where every entry is either $0$ or $1$.
Let $A(k,n)$ be the total number of these matrices such that the sum of the entries in every $2\times k$ window is $k$.
You are given that $A(3,9) = 560$ and $A(4,20) = 1060870$.
Find $A(10^8,10^{16})$. Give your answer modulo $1\,000\,000\,007$.
解决方案
本方案只适用于$k\mid n$的情况。
不难发现,对于$1\le i\le k$,第$i,i+k,i+2k,i+3k,\dots$列中,$1$的个数是相同的。
因此可以只考虑前$k$列的情况。
由于前$2\times k$个格子中,只有$k$个为$1$,因此最多只有$\left\lfloor\dfrac{k}{2}\right\rfloor$列是拥有两个$1$。剩下的$1$中,都被分配到了一个$1$的列。
枚举前$k$个格子中填充两个$1$的列的个数,那么答案为:
如果有$i$列有两个$1$,那么有$i$列没有$1$,有$k-2i$只有一个$1$。那么,$1$的分配方式就有$\dbinom{k}{i}\cdot\dbinom{k-i}{i}=\dfrac{k!}{(n-2i)!(i!)^2}$种。整个$2\times n$的格子中,有$\dfrac{n}{k}\cdot(k-2i)$列是只有一个$1$的,每一列有$2$种填法,由此得到$2^{\frac{n}{k}\cdot(k-2i)}$。最终通过组合得到上式。
代码
1 |
|