[51nod1119] Robot walking square V2 (Dp,lucas theorem)

Source: Internet
Author: User

Title Link: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1119

Test instructions: The Chinese problem surface.

It is easy to know the formula DP (I,J) =DP (i-1,j) +DP (i,j-1), but also know from the top left to the right is n+m-2 step, a table out to see M=1 or n=1 when the result is n or m,m=2 when the result is 3, 6, 10 ...

Guess the result is C (n+m-2,k), with the value of K to find out, K is related to N, k=n-1.

So the result is C (n+m-2,n-1). The large combination of numbers to the prime number modulo, the results can be obtained with Lucas.

1 /*2 ━━━━━┒ギリギリ♂eye! 3 ┓┏┓┏┓┃キリキリ♂mind! 4 ┛┗┛┗┛┃\0/5 ┓┏┓┏┓┃/6 ┛┗┛┗┛┃ノ)7 ┓┏┓┏┓┃8 ┛┗┛┗┛┃9 ┓┏┓┏┓┃Ten ┛┗┛┗┛┃ One ┓┏┓┏┓┃ A ┛┗┛┗┛┃ - ┓┏┓┏┓┃ - ┃┃┃┃┃┃ the ┻┻┻┻┻┻ - */ -#include <algorithm> -#include <iostream> +#include <iomanip> -#include <cstring> +#include <climits> A#include <complex> at#include <fstream> -#include <cassert> -#include <cstdio> -#include <bitset> -#include <vector> -#include <deque> in#include <queue> -#include <stack> to#include <ctime> +#include <Set> -#include <map> the#include <cmath> * using namespacestd; $ #defineFr FirstPanax Notoginseng #defineSC Second - #defineCL Clear the #defineBUG puts ("Here!!!") + #defineW (a) while (a--) A #definePB (a) push_back (a) the #defineRint (a) scanf ("%d", &a) + #defineRll (a) scanf ("%i64d", &a) - #defineRs (a) scanf ("%s", a) $ #defineCIN (a) CIN >> a $ #defineFRead () freopen ("in", "R", stdin) - #defineFWrite () freopen ("Out", "w", stdout) - #defineRep (i, Len) for (int i = 0; i < (len); i++) the #defineFor (I, A, Len) for (int i = (a); I < (len); i++) - #defineCls (a) memset ((a), 0, sizeof (a))Wuyi #defineCLR (A, X) memset ((a), (x), sizeof (a)) the #defineFull (a) memset ((a), 0x7f7f7f, sizeof (a)) - #defineLRT RT << 1 Wu #defineRRT RT << 1 | 1 - #definePi 3.14159265359 About #defineRT return $ #defineLowbit (x) x & (-X) - #defineONECNT (x) __builtin_popcount (x) -typedefLong LongLL; -typedefLong DoubleLD; Atypedef unsignedLong LongULL; +typedef pair<int,int>PII; thetypedef pair<string,int>psi; -typedef PAIR&LT;LL, Ll>PLL; $typedef map<string,int>MSI; thetypedef vector<int>VI; thetypedef vector<ll>VL; thetypedef vector<vl>VVL; thetypedef vector<BOOL>vb; -  in LL N, m; theLL p = 1e9+7; the  Aboutll EXGCD (ll a,ll b,ll &x,ll &y) { the     if(b = =0) { thex=1; they=0; +         returnA; -     } theLL ret = EXGCD (b, a%b, y, x);BayiY-= A/b *x; the     returnret; the } -  -LL INV (ll A,intm) { theLL d, x, y, t =LL (m); theD =EXGCD (A, t, X, y); the     if(d = =1)return(x% t + t)%T; the     return-1; - } the  the ll Cm (ll N, ll M, ll p) { theLL A =1, B =1;94     if(M > N)return 0; the      while(m) { theA= (a*n)%p; theb= (b*m)%p;98m--; Aboutn--; -     }101     returnLL (a) * INV (b, p)%p;102 }103 104 intLucas (ll N, ll M, ll p) { the     if(M = =0)return 1;106     returnLL (Cm (n%p, m%p, P)) * LL (Lucas (n/p, m/p, p))%p;107 }108 109 intMain () { the     //FRead ();111      while(Cin >> N >>m) { then--; m--;113cout << Lucas (n+m, n, p); the     } theRt0; the}

[51nod1119] Robot walking square V2 (Dp,lucas theorem)

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.