Posted By

ldominov on 01/16/13


Tagged


Versions (?)

warshallov


 / Published in: C++
 

implementation of warshall algorithm, dynamic programming, c++

  1. #include <iostream>
  2. #define N 4
  3. using namespace std;
  4.  
  5. int main(){
  6. bool R[N][N]={
  7. {0,1,0,0},
  8. {0,0,0,1},
  9. {0,0,0,0},
  10. {1,0,1,0}
  11. };
  12. for(int k = 0; k<N; k++){
  13. for(int i = 0; i<N; i++){
  14. for(int j = 0; j<N; j++){
  15. R[i][j] = R[i][j] || (R[i][k] && R[k][j]);
  16. }
  17. }
  18. }
  19. cout<<"\nTranzitivno zatvaranje: \n";
  20. for(int i=0;i<N;i++){
  21. for(int j=0;j<N;j++)
  22. cout<<R[i][j]<<" ";
  23. cout<<"\n";
  24. }
  25. int n; cin>>n;
  26. return 0;
  27. }

Report this snippet  

You need to login to post a comment.