Advertisement
KennasSticky

p15_dp

Mar 19th, 2022
986
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <chrono>
  3.  
  4. using namespace std;
  5.  
  6. const int gridsize = 20;
  7.  
  8. long long grid[gridsize+2][gridsize+2];
  9.  
  10. int main() {
  11.  
  12.     // YOU COULD DO THIS OR JUST USE MATH :)
  13.     // 40! / ((20!)^2)
  14.  
  15.     grid[1][1] = 1;
  16.  
  17.     auto start = std::chrono::steady_clock::now();
  18.  
  19.     for (int i = 1; i <= gridsize+1; i++) {
  20.         for (int j = 1; j <= gridsize+1; j++) {
  21.             grid[i][j] += grid[i][j-1] + grid[i-1][j];
  22.         }
  23.     }
  24.  
  25.     auto stop = std::chrono::steady_clock::now();
  26.    
  27.     auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>((stop - start) / 1000);
  28.    
  29.     cout << "Time taken by function: " << duration.count() << " nanoseconds" << endl;
  30.  
  31.     cout << grid[gridsize+1][gridsize+1] << "\n";
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement