Test instructions
There is a rectangle of n * m, starting from (1, 1), each time to reach a lattice in the lower right lattice, to reach (N, m) the number of schemes.
Exercises
Obviously up to min (n-2, m-2) + 1 steps, number of feet K, answer to sum C (n-2, K-1) * C (m-2, K-1)
Code:
#include <bits/stdc++.h>using namespace std;const int mod = 1e9 + 7;const int n = 1e5 + 7; #define LL long longint N, M LL F[n], Ans;map <int, ll> inv;int Pow (int x, int cnt) {int ret = 1;while (CNT) {if (CNT & 1) ret = (LL) ret * X% Mod;x = (LL) x * x% mod;cnt >>= 1;} return ret;} int main () {scanf ("%d%d", &n, &m); F[0] = 1, inv[0] = 1;for (int i = 1; i < N; ++i) {f[i] = f[i-1] * I% mod;inv[i] = Pow (F[i], mod-2);} int lim = min (N-2, m-2); for (int i = 1; I <= lim + 1; ++i) {LL ans1 = f[n-2] * inv[i-1]% mod * inv[n-i-1]% mod; LL ans2 = f[m-2] * inv[i-1]% mod * inv[m-i-1]% Mod;ans = (ans + ans1 * ans2% mod)% MoD;} cout << ans << endl;return 0;}
51nod 1627 instantaneous movement