1049-deg-route

Source: Internet
Author: User

http://www.ifrog.cc/acm/problem/1049

I usually look for the law in these maths problems.

First the violence simulates the previous ones, and then finds (x, y) = (x, y-1) + (x-1, y) gets.

But it's useless. Because to get (x, y-1) These, but also recursive processing, will be GG.

Then find the rule is C (x + y, y)-C (x + y, y-1)

Cannot nothing more yy. Try to match the relationship between X and Y.

Generally must be related to these two numbers, and 2 * x these few relationships.

#include <cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>#defineIOS Ios::sync_with_stdio (False)using namespacestd;#defineINF (0X3F3F3F3F)typedefLong Long intLL; #include<iostream>#include<sstream>#include<vector>#include<Set>#include<map>#include<queue>#include<string>ConstLL MOD = 1e4 +7; ll Quick_pow (ll a,ll b,ll MOD) {//solving the value of a a^b%modLLBase=a%MOD; LL ans=1;//multiplied, so here is 1     while(b) {if(b&1) {ans= (ans*Base)%mod;//If this is a big data, use Quick_mul.        }        Base=(Base*Base)%mod;//Notice//note here that each time the base is its own base timesb>>=1; }    returnans;} ll C (ll n,ll m,ll MOD) {if(n<m)return 0;//To prevent SB from circulating in the time of Lucas    if(n==m)return 1; LL ans1=1; LL Ans2=1; LL MX=max (N-M,M);//this is also necessary. It's about the biggest one.LL mi=n-MX;  for(inti =1; I <= mi; ++i) {ans1= ans1* (mx+i)%MOD; Ans2= ans2*i%MOD; }    return(Ans1*quick_pow (ans2,mod-2, MOD)%mod);//Put it in the last place, or it'll be slow.}ll Lucas (ll n,ll m,ll MOD) {ll ans=1;  while(N && m &&ans) {ans=ans*c (n%mod,m%mod,mod)%MOD; N/=MOD; M/=MOD; }    returnans;} LL Calc (ll X, ll y) {ll ans= (Lucas (2* x, X, MOD) + Mod-lucas (2* x, X +1, MOD))%MOD; returnans;}voidWork () {LL x, y; CIN>> x >>y; if(Y = =0) {cout<<1<<Endl; } Else {        if(x = =y) {cout<< Calc (x, y) <<Endl; } Else{cout<< (Lucas (x + y, y, MOD)-Lucas (x + y, y-1, MoD) + MoD)% mod <<Endl; }    }}intMain () {#ifdef local freopen ("Data.txt","R", stdin);#endif//For (x = 1; x <=; ++x) {//For (y = 0; y <= x; ++y) {//Work ();//        }//cout << Endl;//    }IOS; intT; CIN>>T;  while(t--) work (); return 0;}

1049-deg-route

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.