Explain the end part of 466C

Правка en1, от icode_247, 2018-09-12 17:18:05

Hi, So i tried to solve this problem . And i did understand the first part of the tutorialbut got a little confused at the end. It says that I have to add everything from cnt[0] to cnt[n-1] to get my answer. But to get a faster result they did a different workaround. They created sums[] and worked on it. This is the c++ solution. Now, why would they do this?:

 for(int i = n-2 ; i >= 0 ; --i)
            cnt[i] += cnt[i+1];

and in this :

        for(int i = 0 ; i+2 < n ; ++i) {
            ss += a[i];
            if (ss == s)
                ans += cnt[i+2];
        }

Why i+2?.

Теги #c++, 466c, #dp

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский icode_247 2018-09-12 17:18:05 816 Initial revision (published)