fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int n,f[1001],t[1001],b[1001],result = 0,pos,cnt = 0;
  4. struct dulieu
  5. {
  6. int fi,se,pos;
  7. };
  8. dulieu a[1001];
  9. using namespace std;
  10. bool comp(const dulieu &a,const dulieu &b)
  11. {
  12. return(a.fi*a.se>b.fi*b.se);
  13. }
  14. int main()
  15. {
  16. ios_base::sync_with_stdio(false);
  17. cin.tie(NULL); cout.tie(NULL);
  18. freopen("xephop.inp","r",stdin);
  19. cin>>n;
  20. for (int i = 1 ; i<=n ; ++i)
  21. {
  22. cin>>a[i].fi>>a[i].se;
  23. a[i].pos = i;
  24. f[i] = 1;
  25. }
  26. sort(a+1,a+n+1,comp);
  27. for (int i = 1 ; i<=n ; ++i)
  28. for (int j = 1 ; j<i ; ++j)
  29. if (a[i].fi==a[j].fi && a[i].se==a[j].se)
  30. continue;
  31. else
  32. {
  33. if ((a[i].fi<a[j].fi &&a[i].se<a[j].se) || (a[i].se<a[j].fi && a[i].fi<a[j].se))
  34. {
  35. f[i] = max(f[i],f[j]+1);
  36. t[i] = j;
  37. if (f[i]>result)
  38. {
  39. result = f[i];
  40. pos = i;
  41. }
  42. }
  43. }
  44. cout<<result<<'\n';
  45. while (pos!=0)
  46. {
  47. ++cnt;
  48. b[cnt] = a[pos].pos;
  49. pos = t[pos];
  50. }
  51. for (int i = cnt ; i>=1 ; --i)
  52. cout<<b[i]<<' ';
  53. return(0);
  54. }
  55.  
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
0