Legendary_45's blog

By Legendary_45, history, 5 hours ago, In English
  • Vote: I like it
  • 0
  • Vote: I do not like it

»
5 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

I am not aware of the optimal solution and I am new to DP. but, my thoughts are one element could be the left most element indicating size or rightmost indicating size or inner element.

dp[i][j] -> Bool segment possible index i the block count j

The states can be, if(j=0) -> it can be starting of left most or it can be right most. if(j>0) -> it can be right most or part of segment.

Once I code the above I'll send it here , if it works :)

  • »
    »
    4 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    https://codeforces.me/contest/1741/submission/311736788

    The above gave a TLE, Now I need help in Tabulation

»
4 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

I have one approach. but it will give you tle.

int n;cin>>n;
        vector<int> arr(n);
        scan(arr,n);
        vector<int> dp(n+1,-1);
        auto sol = [&](int i,auto &&sol){
            if(i == n) return 1;
            int &flag = dp[i];
            if(flag != -1) return flag;
            flag = 0;
            for(int j=i+1;j<n;j++){
                const int si = j-i;
                if(arr[i] == si || arr[j] == si){
                    flag |= sol(j+1,sol);
                }
            }
            return flag;
        };
        cout<<(sol(0,sol)? "Yes":"No");
  • »
    »
    4 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    may be this problem should solve by only iterative dp.