Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // INOI_No. of routings.cpp : Defines the entry point for the console application.
- //
- #include <iostream>
- using namespace std;
- long long n, s, d, k;
- long long matrix[75][75][75] = { 0 };
- int main()
- {
- cin >> n;
- for (long long i = 1; i <= n; ++i)
- {
- for (long long j = 1; j <= n; ++j)
- {
- cin >> matrix[i][j][1];
- }
- }cin >> s >> d >> k;
- for (long long t = 2; t <= k; ++t) // matrix power
- {
- for (long long i = 1; i <= n; ++i)//row
- {
- for (long long j = 1; j <= n; ++j)//column
- {
- for (long long f = 1; f <= n; ++f) // multiplication iterator
- matrix[i][j][t] += matrix[i][f][t - 1] * matrix[f][j][1]; // the real work happens here
- //if (t == k){cout << matrix[i][j][t] << "( " << i << "," << j << " )";} testing
- }
- }
- }
- cout << matrix[s][d][k];
- return 0;
- }
Add Comment
Please, Sign In to add comment