I submitted this solution using memoisation but it gave memory limit exceeded. Can someone please help me how to do this problem using recurison??
My submission 77834554
# | User | Rating |
---|---|---|
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 |
# | User | Contrib. |
---|---|---|
1 | cry | 166 |
2 | maomao90 | 163 |
2 | Um_nik | 163 |
4 | atcoder_official | 161 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | nor | 153 |
9 | Dominater069 | 153 |
I submitted this solution using memoisation but it gave memory limit exceeded. Can someone please help me how to do this problem using recurison??
My submission 77834554
Name |
---|
hi, the thing is that your states are not exactly okay. First you have a dp(pos, string you are creating) that means that for every position [1,N] you will have a 2^7 possible strings and you are storing them all. Also in this dp you do not really know how many k's you have left since you are not storing that anywhere. Try to see this problem as subset sum problem, being dp[pos][k] = true if there is a way to get a valid number using this k sticks. Now your dp will only give true or false and you can then only try to recover the possible string and always taking the biggest number that gives you a valid answer. For example if you call helper(0,k) and this gives true then there is at least one valid number and you can reconstruct it like this:
I modified some parts of your code to make it clear https://ideone.com/vKMsot , i submited it in cf but the judge is down now so i do not know if it gave ac or no, but i guess it will. You can also look at my code which is basically the same idea: https://codeforces.net/contest/1341/submission/77894917
edit: cf is up now and it got accepted https://codeforces.net/contest/1341/submission/77908699
hope it helps :)