ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1012. K-based Numbers. Version 2

Runtime error , Case 8
Posted by Sarvagya Agarwal 20 Jan 2017 11:30
Why does this give runtime error #8 .
n = int(raw_input())
k = int(raw_input())
dp = [[-1 for x in xrange(15)]for y in xrange(1910)]
def solve(index,prev) :
if(index > n ) :
return 1
if(dp[index][prev] != -1) :
return dp[index][prev]
res = 0
start = 0
if(index == 1) :
start = 1
for i in xrange(start,k) :
if(prev == 0 and i == 0) :
continue
res = res + solve(index+1,i)
dp[index][prev] = res ;
return  res
print solve(1,0)
Re: Runtime error , Case 8
Posted by Vladimir Putin 5 Jul 2019 09:39
Same for me, solution is python3.
Re: Runtime error , Case 8
Posted by Vladimir Putin 6 Jul 2019 10:17
You have to check for recursion depth exceeded. Do it iterative.