We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I think this code is better than the editorial code to understand! First, calculate all combinations from 1 to 2000 using this fromula (ncR=(n-1)c(R-1)+(n-1)cR) .Then just find the appropriate result according to the problem satement!
#include<bits/stdc++.h>#define ___ ios_base::sync_with_stdio(false);cin.tie(NULL);#define div 1000000007usingnamespacestd;intcom[2017][2017];intmain(){intn,r,a,b,c;for(n=0;n<=2000;n++){for(r=0;r<=n;r++){if(r==0||r==n)com[n][r]=1;elsecom[n][r]=(com[n-1][r-1]+com[n-1][r])%1000000007;}}cin>>c;while(c--){cin>>a>>b;cout<<com[a+b-1][b-1]<<endl;}return0;}
Sherlock and Permutations
You are viewing a single comment's thread. Return to all comments →
I think this code is better than the editorial code to understand! First, calculate all combinations from 1 to 2000 using this fromula (ncR=(n-1)c(R-1)+(n-1)cR) .Then just find the appropriate result according to the problem satement!