Editorial for Đếm dãy số
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Dễ dàng nhận thấy rằng mọi dãy số thỏa mãn đều không vượt quá phần tử.
Gọi
,
là số dãy số độ dài
với tổng các phần tử bằng
. Khi đó:
với mọi
.
với mọi
.
với mọi
,
.
Ta có thể dễ dàng tính mảng với độ phức tạp
.
Nhận xét rằng việc tính toán chỉ cần dựa trên các
với
, nên ta có thể sử dụng Prefix Sum để tối ưu hóa.
Độ phức tạp: .
Comments