daily pastebin goal
28%
SHARE
TWEET

NUMROUTE

Taksh Jan 1st, 2018 23 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // INOI_No. of routings.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include <iostream>
  5. using namespace std;
  6. long long n, s, d, k;
  7. long long matrix[75][75][75] = { 0 };
  8. int main()
  9. {
  10.     cin >> n;
  11.     for (long long i = 1; i <= n; ++i)
  12.     {
  13.         for (long long j = 1; j <= n; ++j)
  14.         {
  15.             cin >> matrix[i][j][1];
  16.         }
  17.     }cin >> s >> d >> k;
  18.     for (long long t = 2; t <= k; ++t)  // matrix power
  19.     {
  20.         for (long long i = 1; i <= n; ++i)//row
  21.         {
  22.             for (long long j = 1; j <= n; ++j)//column
  23.             {
  24.                 for (long long f = 1; f <= n; ++f)  // multiplication iterator
  25.                     matrix[i][j][t] += matrix[i][f][t - 1] * matrix[f][j][1]; // the real work happens here
  26.                 //if (t == k){cout << matrix[i][j][t] << "( " << i << "," << j << " )";} testing
  27.             }
  28.         }
  29.     }
  30.     cout << matrix[s][d][k];
  31.     return 0;
  32. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top