Problem Name — Separate It
Statement
You are given an array $$$a$$$ containing $$$n$$$ elements and another array $$$b$$$ containing $$$m$$$ elements. ( Both are 0 indexed ) You want to separate $$$a$$$ into $$$m$$$ non-empty contiguous subarrays, such that each element belongs to exactly one subarray.
Also, the sum of elements of
Unable to parse markup [type=CF_MATHJAX]
) should be divisible by $$$b_r$$$.Find the total number of way to seperate $$$a$$$ into $$$m$$$ subarrays fulfilling the given conditions, modulo $$$10^9 + 7$$$
Input Format
$$$n$$$ $$$m$$$
Unable to parse markup [type=CF_MATHJAX]
Unable to parse markup [type=CF_MATHJAX]
First line contains two space separated integers $$$n$$$ and $$$m$$$.
Second line contains $$$n$$$ space separated integers denoting array $$$a$$$.
Third line contains $$$m$$$ space separated integers denoting array $$$b$$$.
Constraints
Unable to parse markup [type=CF_MATHJAX]
Unable to parse markup [type=CF_MATHJAX]
$$$1 \le a_i \le 10^9$$$, where
Unable to parse markup [type=CF_MATHJAX]
Unable to parse markup [type=CF_MATHJAX]
, whereUnable to parse markup [type=CF_MATHJAX]
Examples
Source — Infosys Coding Round on 21st Jan.
I have tried a lot and I was only able to come up with a
Unable to parse markup [type=CF_MATHJAX]
approach using DP, but couldn't optimize further.If anyone has any idea how to solve it, or knows any similiar problem, please help.