Advertisement
Kali_prasad

ncr

May 26th, 2022
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. #pragma GCC optimize ("O3")
  2. #pragma GCC target ("sse4")
  3.  
  4. #include <bits/stdc++.h>
  5. using namespace std;
  6.  
  7. typedef long long ll;
  8. typedef pair<int, int> pii;
  9. typedef pair<string,int> psi;
  10. typedef unordered_map<int,int> mii;
  11. typedef unordered_map<long long,long long> mll;
  12. typedef unordered_map<string,int> msi;
  13. typedef unordered_map<char,int> mci;
  14. typedef unordered_set<int> si;
  15. typedef unordered_set<long long> sll;
  16. typedef unordered_set<string> ss;
  17. typedef unordered_set<char> sc;
  18. typedef map<int,int> ormii;
  19. typedef map<long long,long long> ormll;
  20. typedef map<string,int> ormsi;
  21. typedef map<char,int> ormci;
  22. typedef set<int> orsi;
  23. typedef set<long long> orsll;
  24. typedef set<string> orss;
  25. typedef set<char> orsc;
  26. typedef vector<int> vi;
  27. typedef vector<string> vs;
  28. typedef vector<char> vc;
  29. typedef vector<ll> vll;
  30. typedef vector<vector<int>> vvi;
  31. typedef vector<vector<string>> vvs;
  32. typedef vector<vector<ll>> vvll;
  33.  
  34. #define FOR(i, a, b) for (auto i=a; i<=(b); i++)
  35. #define FORd(i,b,a) for (int i =b; i >= a; i--)
  36. #define sortinc(v) sort(v.begin(),v.end())
  37. #define sortdec(v) sort(v.rbegin(),v.rend())
  38. #define sz(x) (int)(x).size()
  39. #define mp make_pair
  40. #define pb push_back
  41. #define pob pop_back
  42. #define pf push_front
  43. #define pof pop_front
  44. #define fi first
  45. #define se second
  46. #define ins insert
  47.  
  48. const int MOD = 1e9+7;
  49. //type functions here
  50.  
  51. int m(int n)
  52. {
  53. return n%MOD;
  54. }
  55.  
  56. int main() {
  57. ios_base::sync_with_stdio(false);
  58. cin.tie(NULL);
  59. int n=2000;
  60. vvll dp(n+1,(vector<ll>(n+1,0)));//2000 elements can be picked from 2000 items at max
  61. //no.of cols=no.of items picked----->j
  62. //no.of rows=no.of items existing--->i
  63. FOR(j,0,n) dp[0][j]=0;//if there's no items ,no way we can pick them (impossibility is denoted by 0)
  64. FOR(i,0,n) dp[i][0]=1;//0 items can be picked by not picking them that's the only way note:- 0c0 is 1
  65. FOR(i,1,n)//building every row except 0th row
  66. {
  67. FOR(j,1,i)//building every cols except 0th col no.of cols in a row can be at max rowth number
  68. {
  69. dp[i][j]=((dp[i-1][j])%MOD/*if element not picked now j elements picked from i-1 only*/
  70. +(dp[i-1][j-1])%MOD)%MOD/*if element picked now j-1 elements picked from i-1 only*/;
  71. }
  72. }
  73. int tc=1;
  74. cin>>tc;
  75. FOR(w,1,tc)
  76. {
  77. int n,r;
  78. cin>>n>>r;
  79. cout<<dp[n][r]<<endl;
  80. // cout<<"hello";
  81. }
  82. return 0;
  83. }
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement