fork download
  1. // @adi28galaxyak
  2. // Content: CDVA1607
  3.  
  4. #include "bits/stdc++.h"
  5. using namespace std;
  6.  
  7. typedef long long ll;
  8. typedef vector<int> vi;
  9. typedef vector< vi > vii;
  10. typedef pair<int, int> pii;
  11. #define FF first
  12. #define SS second
  13. #define pb(v) push_back(v)
  14. #define mp(x,y) make_pair(x, y)
  15.  
  16. #define NITRO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  17. #define s(n) scanf("%d",&n)
  18. #define rep(i,start,end) for(int i = start;i<end;i++)
  19.  
  20. const int M = 1e9 + 7;
  21. ll ncr[4005][4005];
  22.  
  23. void calNCR(){
  24. rep(i,1,4001){
  25. rep(j,0,i+1){
  26. if(!j) ncr[i][j] = 1;
  27. else ncr[i][j] = (ncr[i-1][j]%M + ncr[i-1][j-1]%M)%M;
  28. }
  29. }
  30. }
  31.  
  32. int main(){
  33. if(false) {
  34. freopen("inp01.txt","r",stdin);
  35. freopen("testout01.txt","w",stdout);
  36. }
  37. NITRO;
  38.  
  39. rep(i,0,4005)
  40. rep(j,0,4005) ncr[i][j] = 0;
  41. ncr[0][0] = 1;
  42. calNCR();
  43.  
  44. int tt, n, q, i, k;
  45. cin>>tt;
  46. ll power[4005];
  47. power[0] = 1;
  48. rep(i,1,4005) power[i] = (power[i-1]*2)%M;
  49.  
  50. while(tt--){
  51. cin>>n>>q;
  52. while(q--){
  53. cin>>i>>k;
  54. if(k>i) puts("0");
  55. else {
  56. //cout<<ncr[i-1][k-1]%M<<" "<<power[n-i]<<endl;
  57. ll ans=(ncr[i-1][k-1]%M)*power[n-i]%M;
  58. printf("%lld\n",ans%M);
  59. }
  60. }
  61. }
  62. }
  63.  
Success #stdin #stdout 0.89s 128704KB
stdin
Standard input is empty
stdout
Standard output is empty