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 | 3831 |
3 | Radewoosh | 3646 |
4 | jqdai0815 | 3620 |
4 | Benq | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | gamegame | 3386 |
10 | ksun48 | 3373 |
# | User | Contrib. |
---|---|---|
1 | cry | 164 |
1 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 160 |
5 | -is-this-fft- | 158 |
6 | awoo | 157 |
7 | adamant | 156 |
8 | TheScrasse | 154 |
8 | nor | 154 |
10 | 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://mirror.codeforces.com/contest/1341/submission/77894917
edit: cf is up now and it got accepted https://mirror.codeforces.com/contest/1341/submission/77908699
hope it helps :)