51nod 1627 instantaneous movement

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.