1 #include <iostream> 2 #include <algorithm> 3 #include <cstdlib> 4 #include <cstring> 5 using namespace std; 6 7 struct show 8 { 9 int start; 10 int end; 11 }; 12 bool cmp(show a, show b) { 13 return a.end < b.end; 14 } 15 show a[101]; 16 int f1[101]; 17 int f2[101]; 18 19 int dp(int n, show *a) { 20 memset(f1, 0, sizeof(f1)); 21 memset(f2, 0, sizeof(f2)); 22 23 24 for (int i = 0; i < n;i++) { 25 for (int j = a[i].end; j <=100; j++) 26 f2[j] = max(f1[j], f1[a[i].start] + 1); 27 memcpy(f1, f2, sizeof(f2)); 28 } 29 return f1[100]; 30 } 31 32 33 34 int main() { 35 int n; 36 while (cin>>n&&n!=0) 37 { 38 for (int i = 0; i < n; i++) 39 cin >> a[i].start >> a[i].end; 40 sort(a, a + n, cmp); 41 cout << dp(n, a) << endl; 42 } 43 44 }