fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. struct sub
  6. {
  7. long long so;
  8. long long vt;
  9. };
  10. sub a[205];
  11. int n,kq,f[205];
  12.  
  13. long long better(sub a, sub b)
  14. {
  15. return a.so<b.so;
  16. }
  17.  
  18. void nhap()
  19. {
  20. ifstream fi("subset.inp");
  21. fi>>n;
  22. for (int i=1;i<=n;i++)
  23. {
  24. fi>>a[i].so;
  25. a[i].vt=i;
  26. }
  27. sort(a+1,a+1+n,better);
  28. }
  29.  
  30. void xuly()
  31. {
  32. for (int i=1;i<=n;i++)
  33. {
  34. f[i]=1;
  35. }
  36. for (int i=1;i<=n;i++)
  37. {
  38. int maxx =0;
  39. for (int j=1;j<=i-1;j++)
  40. {
  41. if((a[i].so % a[j].so ==0) && (j>maxx))
  42. maxx=f[j];
  43. }
  44. f[i]=maxx+1;
  45. kq=max(kq,f[i]);
  46. }
  47. }
  48. void ghi()
  49. {
  50. ofstream fo("subset.out");
  51. fo<<kq<<endl;
  52. for (int i=1;i<=kq;i++)
  53. {
  54. for (int j=1;j<=n;j++)
  55. if (f[j]==i)
  56. {
  57. fo<<a[j].vt<<" ";
  58. }
  59. fo<<endl;
  60. }
  61. }
  62. int main()
  63. {
  64. nhap();
  65. xuly();
  66. ghi();
  67. }
  68.  
Success #stdin #stdout 0s 5520KB
stdin
Standard input is empty
stdout
Standard output is empty