codevs 1515 跳

來源:互聯網
上載者:User

標籤:

/*畫矩陣找規律發現是楊輝三角 Cg (i,j)= C (i+j,i);貪心走的話 沿著0行(列)一直走然後拐直角拐彎後每個格子都累加 Cg (n,0) + Cg (n,1) + Cg (n,2) + ... +Cg (n,m)  有n>m即  C(n+0,n) + C (n+1,n) + C (n+2,n) + ... +C (n+m,n) 上式 = C (n+m+1,m);然後 ans = n + C (n+m+1,m);考慮到n m很大 用Lucas定理 之前敲得Lcs都是用數組存階乘 哪裡的mod較小這裡10^9+7 顯然存不下 所以直接每次都求一下 */#include<iostream>#include<cstdio>#include<cstring>#define ll long long#define mod 1000000007using namespace std;ll Mi(ll a,ll b){    if(b==0)return 1;    ll x=Mi(a,b/2)%mod;    x=x*x%mod;    if(b&1)x=x*a%mod;    return x;}ll C(ll n,ll m){    if(m>n)return 0;    ll nmj=1,mj=1;    for(ll i=n;i>=n-m+1;i--)      nmj=nmj*i%mod;    for(int i=1;i<=m;i++)//開始以為這句會導致T 後然認真讀讀題目發現想多了0.0       mj=mj*i%mod;    return (nmj*Mi(mj,mod-2))%mod;}ll Lcs(ll n,ll m){    if(m==0)return 1;    return C(n%mod,m%mod)*Lcs(n/mod,m/mod);}int main(){    ll n,m;    cin>>n>>m;    if(n<m)swap(n,m);    printf("%lld",(n+Lcs(n+m+1,m))%mod);}

 

codevs 1515 跳

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.