Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // http://vinhdinhcoder.net/Problem/Details/5064
- #include <bits/stdc++.h>
- using namespace std;
- #define ms(s,n) memset(s,n,sizeof(s))
- #define all(a) a.begin(),a.end()
- #define present(t, x) (t.find(x) != t.end())
- #define sz(a) int((a).size())
- #define FOR(i, a, b) for (int i = (a); i < (b); ++i)
- #define FORd(i, a, b) for (int i = (a) - 1; i >= (b); --i)
- #define pb push_back
- #define pf push_front
- #define fi first
- #define se second
- #define mp make_pair
- #define endl "\n"
- typedef long long ll;
- typedef unsigned long long ull;
- typedef long double ld;
- typedef pair<int,int> pi;
- typedef vector<int> vi;
- typedef vector<pi> vii;
- const int MOD = (int) 1e9+7;
- const int INF = (int) 1e9+2804;
- inline ll gcd(ll a,ll b){ll r;while(b){r=a%b;a=b;b=r;}return a;}
- inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
- bool ngtoCungNhau ( ll a, ll b ){
- if ( gcd(a,b) ==1 ) return true ;
- return false ;
- }
- bool cmp ( pair < ll , ll > a, pair <ll, ll > b ){
- return a.first < b.first ;
- }
- int main(){
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- ll n;
- cin >> n;
- pair < ll, ll > a [n];
- ll dp[n];
- for (int i=0;i<n;i++){
- cin >> a[i].first >> a[i].second ;
- dp[i]=1;
- }
- sort ( a, a+n, cmp );
- // sắp xếp theo thứ tự tăng của ngày tháng trong năm
- // điều kiện sort khác với điều kiện của dp
- // sort chỉ để làm thuận tiện hơn thôi chứ sort xong chưa chắc đã là kết quả của bài toán
- // ví dụ như bài này thì yêu cầu của bài toán là chọn những cặp ngày không bị trùng time với nhau
- // mà nếu mình sort với điều kiện của đề bài ngay thì những cặp không thoả điều kiện sẽ không thể sort đc => kết quả không đúng
- // cout <<"____________"<<endl;
- // FOR(i,0,n) cout << a[i].first <<" "<<a[i].second <<endl;
- ll res =0 ;
- for (int i=1;i<n;i++){
- for (int j=0;j<i;j++){
- if (a[i].first > a[j].second && dp[i]<dp[j]+1){
- dp[i]= dp[j]+1;
- }
- }
- res = max( res, dp[i]);
- }
- cout << res;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment