Comments
On t_t_mWriting notes during cp, 3 years ago
+6

Inspired by galen_colin

I maintain this Google Sheet CP sheet

Thanks! Got it. I made a mistake with my reasoning.

I did consider this case in my dp. I did this. My code failed anyways.

if(adjList[u].size() == 1) dp[u] += 1(Below is the dfs)
void dfs(int u, vector<vector<int>> &adjList, vector<int> &dp){
    int answer = 0;
    if(adjList[u].size() == 0){
        dp[u] = 1;
        return;
    }

    for(int v: adjList[u]){
        dfs(v, adjList, dp);
        answer += dp[v];
    }
    dp[u] = answer;
    if(adjList[u].size() == 1) dp[u] += 1;
}

Thanks

In Problem E, can anyone explain why we would ever do this? ->If card i is used in the longest non-decreasing subsequence, then the maximum answer is the maximum value of dist(j,i) for all j∈Di.

Can someone give a small counter example where doing just this (->If card i is not used in the longest non-decreasing subsequence, then the maximum answer is the sum of dp values of all of the children of i.) will fail.