Guest User

uyg

a guest
Jan 15th, 2020
63
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. void gen(int k);
  5. int viz[31],x[31],sol[31],S,Smax,a[31],n,i,j;
  6. int main()
  7. {
  8.  
  9. cin>>n;
  10. for( i=1; i<=n; i++)
  11. for( j=1; j<=n; j++)
  12. cin>>a[i][j];
  13. for( j=1; j<=n; j++)
  14. {
  15. S=a[1][j];
  16. viz[j]=1;
  17. gen(2);
  18. viz[j]=0;
  19. }
  20.  
  21. return 0;
  22. }
  23. void gen(int k)
  24. {
  25. if(k==n+1)
  26. {
  27. if(S>Smax)
  28. for( i=1; i<=n; i++)
  29. sol[i]=x[i];
  30. }
  31. else for( j=1; j<=n; j++)
  32. if(!viz[j])
  33. {
  34. S+=a[k][j];
  35. viz[j]=1;
  36. x[k]=j;
  37. gen(k+1);
  38. viz[j]=0;
  39.  
  40. }
  41. }
RAW Paste Data