https://leetcode.com/problems/delete-columns-to-make-sorted-iii/

class Solution {
public:
    int minDeletionSize(vector<string>& A) {
        int N = A[0].length();
        bool all;
        vector<int> result;
        result.resize(N);
        fill(result.begin(), result.end(), 1);
        for (int i = N - 2; i >= 0; i--){
            for (int j = i + 1; j < N; j++){
                all = true;
                for (string line : A) {
                    if (line[i] > line[j]) {
                        all = false;
                        break;
                    }
                }
                if (all) {
                    result[i] = max(result[i], result[j]+1);
                }
            }
        }
        return N - *max_element(result.begin(), result.end());
    }
};