Constraints: 1<=n<=200 1<=k<=10
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
4 | atcoder_official | 161 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
Constraints: 1<=n<=200 1<=k<=10
Название |
---|
Hint: $$$DP$$$ in $$$O(N^2*2*K)$$$
Please elaborate the approach if possible. Will really appreciate it.
Let $$$DP_{i j p q}$$$ the number of different strings using the first $$$i$$$ chars from the string, such that $$$j$$$ is the balance between opening and closing brackets, such that if $$$p = 0$$$ then the current char is an opening bracket and if $$$p = 1$$$ then the current char is a closing bracket, such that the last $$$q$$$ chars from the string are the same.
I will let you think about the $$$DP$$$ transitions.
Me too , it's a dp problem , i found it on atcoder DP Educontest
Plz mention if possible the contest where you encountered such question or similar question.
You've received a hint that the solution is DP, but that hasn't helped you, so perhaps you're missing an easy test of whether a given sequence is valid.
If you model opening brackets as +1 and closing brackets as -1, then for a sequence to be valid, each prefix sum must be non-negative, and the total sum must be 0. It is easy to derive this rule by considering how one would match the bracket pairs with a stack going left-to-right.
Given this, you should have enough hints to build a DP state and from that see the transitions and the computation.
If you are still struggling, try to write (or imagine writing) a backtracking solution that checks all possibilities (i.e. replaces each ? by 0 or 1 recursively). This is obviously an exponential solution, but the information you end up needing in your recursion is usually a great candidate for a DP state (that's a general advice for DP problems).
writing recursion solution to check all possibilities , it's quiet easy the only problem that i'm facing is How to memoize those small substrings
example : ????(((????)))
just from the first [????] in the beginning , how can i store it for the next [????]
I am not sure I understand the question. If you are writing a recursion to check all possibilities, you're not remembering any strings. Any time you come to a "?" you branch out the recursion with a call that treats it as "0" and then another that treats it as "1".
If that's the case, your recursion state should be describable with only a few integers (remember to use the +1/-1 check for validity I described, instead of keeping any substrings as state).