Advertisement
AlexAvram

Untitled

Nov 17th, 2024
8
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. ifstream f("date.in");
  5. ofstream g("date.out");
  6. bool mat[101][101];
  7. int c[101];
  8. int main()
  9. {
  10. int n, p; f>>n>>p;
  11. for (int i=1; i<=n; ++i)
  12. for (int j=1; j<=n; ++j)
  13. f>>mat[i][j];
  14.  
  15. int s, cnt, cmax=-1;
  16. c[1]=1;
  17. for (int i=2; i<=n; ++i)
  18. {
  19. s=0, cnt=1;
  20. for (int j=1; j<=i; ++j)
  21. if (mat[i][j])
  22. ++cnt, s+=c[j];
  23. c[i]=cnt*(cnt+1)/2-s;
  24. if (c[i]>cmax)
  25. cmax=c[i];
  26. }
  27.  
  28. if (p>cmax)
  29. {
  30. int x=p-cmax, t=cmax;
  31. for (int i=n-x+1; i<=n; ++i)
  32. c[i]=++t;
  33. }
  34. for (int i=1; i<=n; ++i)
  35. g<<c[i]<<" ";
  36. return 0;
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement