Блог пользователя saketkumarsingh

Автор saketkumarsingh, 5 месяцев назад, По-английски

I was trying to solve this question Problem using the concept that answer would be the longest non increasing sequence but it fails on some test cases idk why? Please help me sort it out. Here is my Soln: ~~~~~

#include <bits/stdc++.h>
using namespace std;

int find_lis(vector<int> a) {
    vector<int> dp;
    for (int i : a) {
        int pos = upper_bound(dp.begin(), dp.end(), i)- ``dp.begin();
        if (pos == dp.size()) {
            // we can have a new, longer increasing subsequence!
            dp.push_back(i);
        } else {
            // oh ok, at least we can make the ending element smaller
            dp[pos] = i;
        }
    }
    return dp.size();
}
int main(){
    ifstream fin("cowjog.in");
    ofstream fout("cowjog.out");
    int  n,t;fin>>n>>t;
    vector<vector<int>> v(n, vector<int>(2));
    for(int i=0;i<n;i++) { int x,y;fin>>x>>y; v[i][0]=x, v[i][1]=y; }

    sort(v.begin(), v.end());
    
    vector<int> vec(n);
    for(int i=0;i<n;i++){
        vec[i]=(v[i][0]+t*v[i][1]);
    }
    reverse(vec.begin(), vec.end());
    fout<<find_lis(vec)<<endl;
}

~~~~~

Теги dp, lis
  • Проголосовать: нравится
  • +9
  • Проголосовать: не нравится

»
5 месяцев назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

i think it should be int pos = lower_bound(dp.begin(), dp.end(), i)- ``dp.begin();

»
5 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

LIS isn't the way to go. Here is the answer if you're stuck.

»
5 месяцев назад, # |
  Проголосовать: нравится -6 Проголосовать: не нравится

I don't understand dp, but I can only wish you good luck.