ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 백준 11568번: 민균이의 계략
    최장 증가 수열(Long Increasing Subsequence) 2018. 7. 1. 19:43
    반응형

    https://www.acmicpc.net/problem/11568

     

    LIS 문제

     

    키워드 - DP, LIS

    O(n^2)

     

    Source

     

    #include <iostream>
    #include <sstream>
    #include <string>
    #include <algorithm>
    #include <functional>
    #include <vector>
    #include <list>
    #include <queue>
    #include <deque>
    #include <map>
    #include <set>
    #include <stack>
    
    using namespace std;
    
    #define MAX_SIZE 100
    #define INF 0x7fffffff
    #define CENDL "\n"
    #define ll long long
    /*
    * @memory  - 2380 kb
    * @time    - 56 ms
    */
    
    
    int arr[1001];
    int dp[1001];
    
    int main() {
    
        cin.tie(0);
        std::ios::sync_with_stdio(false);
    
        int n; cin >> n;
        for(int i=1; i<=n; i++) {
            cin >> arr[i];
        }
    
        dp[1]=1;
    
        int sol = 1;
        for(int i=2; i<=n; i++){
            for(int j=i; j>=0; j--){
                if(arr[j] < arr[i]){
                    dp[i] = max(dp[i],dp[j]+1);
                }
            }
            sol = max(sol, dp[i]);
        }
    
        cout << sol << CENDL;
    
        return 0;
    }
     

     

    반응형

    댓글

Designed by Tistory.