in the name of god
i'm new to python and i write recursion function in it for solving this problem and i get runtime error on test 5.
why recursion function in python gets runtime error?
its ok in c++.
thanks for your helping!
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3773 |
3 | Radewoosh | 3646 |
4 | ecnerwala | 3624 |
5 | jqdai0815 | 3620 |
5 | Benq | 3620 |
7 | orzdevinwang | 3612 |
8 | Geothermal | 3569 |
8 | cnnfls_csy | 3569 |
10 | gyh20 | 3447 |
# | User | Contrib. |
---|---|---|
1 | awoo | 161 |
2 | maomao90 | 160 |
3 | nor | 157 |
4 | atcoder_official | 156 |
4 | cry | 156 |
6 | -is-this-fft- | 155 |
7 | maroonrk | 154 |
8 | adamant | 153 |
9 | Um_nik | 151 |
10 | djm03178 | 146 |
in the name of god
i'm new to python and i write recursion function in it for solving this problem and i get runtime error on test 5.
why recursion function in python gets runtime error?
its ok in c++.
thanks for your helping!
Name |
---|
Auto comment: topic has been updated by ya_hossein (previous revision, new revision, compare).
Auto comment: topic has been updated by ya_hossein (previous revision, new revision, compare).
Auto comment: topic has been updated by ya_hossein (previous revision, new revision, compare).
The default limit on recursive calls in Python is 1000 or 10000. You can increase it by calling
sys.setrecursionlimit(...)
.thanks so much
i don't know why but after adding sys it doesn't work. here is my submission
Further to the comments about recursion limits, you may also find that even changing the max depth does not solve your problem. I certainly had that experience.
I found a solution in this thread and specifically this comment — it turns your recursion function into a non-recursive stack implementation.
Note that all recursions can be achieved using stacks instead, and (using DFS as an example), it is possible to code a DFS recursion using stacks instead, thus eliminating any concerns.
it doesn't work after using bootstrap...
did i forget something?
here is link
When you call the function from within itself, you must precede the call with "yield", so the correct version looks like this:
arr1[x] = num1[x] + max((yield(ans0(x + 1))), (yield(ans0(x + 2))))
and the same for your other function
The solutions are not equivalent.
When they are, the next thing is to learn to increase stack size in Python. You can refer here for an example.