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

Автор angry_pikachu, история, 2 года назад, По-английски

Source — Link

Given a string with lowercase letters and “?” where each “?” can be replaced by any lowercase character, find the total number of strings such that the first and last characters are the same and no adjacent characters are the same.

I am still new to DP, help would be appreciated

Полный текст и комментарии »

  • Проголосовать: нравится
  • +6
  • Проголосовать: не нравится

Автор angry_pikachu, история, 2 года назад, По-английски

I am getting error

prog.cpp: In lambda function:

prog.cpp:118:28: error: use of ‘dfs’ before deduction of ‘auto’

118 | for(ll it: nde[i]) dfs(it,fren[i]);

In this code , ll means long long, nde[i] is a vector of int

auto dfs = [&](int i,int x)->void{
        fren[i]+=x;
        for(ll it: nde[i]) dfs(it,fren[i]);
    };
dfs(0,0);

Writing a blog in codeforces for first time

C++ 17 online compiler

Worked using

    function<void(int, int)> dfs = [&](int i, int x) -> void {
        fren[i] += x;
        for (ll it : nde[i])
            dfs(it, fren[i]);
};

Also by changing vector<int> nde[n] to vector<vector<int>> nde(n) and by using the function

    auto dfs = [&](int i,int x, auto &&dfs)->void{
        fren[i]+=x;
        for(ll it: nde[i]) dfs(it,fren[i], dfs);
    };
    dfs(0,0,dfs);

Полный текст и комментарии »

  • Проголосовать: нравится
  • -21
  • Проголосовать: не нравится