fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef pair<int,int> ii;
  5. typedef vector<ii> vii;
  6. typedef vector<int> vi;
  7. typedef long double ld;
  8. typedef long long ll;
  9. const char *fi ="";
  10. const char *fo ="";
  11. const int MAXN = 10000;
  12. const ld EPS = 1e-9;
  13. fstream f;
  14.  
  15.  
  16. struct point{
  17.  
  18. int a,b,c;
  19.  
  20. };
  21.  
  22. bool compare (point x,point y){
  23. if (x.c<y.c) return true;
  24. }
  25.  
  26. int main()
  27. {
  28. //freopen("t.txt","r",stdin);
  29. int t;
  30. int n;
  31. while (1){
  32. cin>>n;
  33. if (n==0) break;
  34. point p[n+1];
  35.  
  36. for (int i=1;i<=n;i++) {
  37. cin>>p[i].a>>p[i].b;
  38. if (p[i].a<=p[i].b) swap(p[i].a,p[i].b);
  39. p[i].c=p[i].a*p[i].b;
  40.  
  41. }
  42.  
  43. sort (p+1,p+n+1,compare);
  44. int l[n+1],MAX=0;
  45.  
  46. for (int i=1;i<=n;i++ ){
  47. l[i]=1;
  48. for (int j=1;j<i;j++){
  49.  
  50. if (p[j].a<=p[i].a && p[j].b<=p[i].b){
  51. l[i]=max (l[i],l[j]+1);
  52. if (l[i]>MAX){
  53. MAX=l[i];
  54. }
  55. }
  56.  
  57. }
  58.  
  59. }
  60. cout<<MAX<<endl;
  61.  
  62.  
  63. }
  64. cout<<"*";
  65. return 0;
  66. //cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";//cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  67. }
  68.  
Time limit exceeded #stdin #stdout 5s 8388607KB
stdin
Standard input is empty
stdout
Standard output is empty