Advertisement
a53

SumMax

a53
Feb 4th, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3.  
  4. int x[11], uz[11], a[11][11] ,n , smax;
  5.  
  6. ifstream fin("summax.in");
  7. ofstream fout("summax.out");
  8.  
  9. void back(int k){
  10. for(int i=1 ; i<=n ; ++i)
  11. if(uz[i]==0)
  12. {
  13. uz[i]=1;
  14. x[k]=i;
  15. if(k==n)
  16. {
  17. int s = 0;
  18. for( int j=1;j<=n;j++)
  19. s += a[j][x[j]];
  20. if(s>smax)
  21. {
  22. smax = s;
  23. }
  24. }
  25. else
  26. back(k+1);
  27. uz[i]=0;
  28. }
  29. }
  30. int main()
  31. {
  32.  
  33. fin>>n;
  34. for(int i=1;i<=n;++i)
  35. for(int j=1;j<=n;++j)
  36. fin >> a[i][j];
  37. back(1);
  38. fout << smax;
  39. return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement