%I #28 Jul 20 2023 07:23:28
%S 0,3,1,2,2,12,1,2,2,4,2,10,15,1,2,2,4,2,10,20,1,2,2,4,2,10,13,8,2,10,
%T 2,15,7,15,25,17,53,1,2,2,4,2,10,65,1,2,2,4,2,10,13,8,2,10,2,15,7,15,
%U 72,1,2,2,4,2,10,24,18,52
%N a(n) is the maximum number of locations 1..n-1 which can be visited in a single path starting from i = n-1, where jumps from location i to i +- a(i) are permitted (within 1..n-1) and a term can be visited up to three times.
%C When a location is visited more than once, each such visit counts in a(n).
%C a(0)=0 is no terms before n=0 so an empty path.
%e For n=6, the following is the longest chain of jumps starting from i = n-1 = 5,
%e 1 2 3 4 5 location number i
%e 0, 3, 1, 2, 2 a(i)
%e 1<----
%e ->2
%e 3<----
%e ------->2
%e 1<----
%e ->2
%e 3<----
%e ------->2
%e 1<----
%e ->2
%e 3<----
%e It visited the terms 2,1,2,3 three times in a loop, which gives a total of 12 terms, so a(6)=12.
%o (Python)
%o def A(lastn,times=3,mode=0):
%o a,n=[0],0
%o while n<lastn:
%o d,i,v,o,g,r=[[n]],0,1,[],0,0
%o while len(d)>0:
%o if len(d[-1])>v: v,o=len(d[-1]),d[-1][:]
%o if d[-1][-1]-a[d[-1][-1]]>=0:
%o if d[-1].count(d[-1][-1]-a[d[-1][-1]])<times:g=1
%o if d[-1][-1]+a[d[-1][-1]]<=n:
%o if d[-1].count(d[-1][-1]+a[d[-1][-1]])<times:
%o if g>0: d.append(d[-1][:])
%o d[-1].append(d[-1][-1]+a[d[-1][-1]])
%o r=1
%o if g>0:
%o if r>0: d[-2].append(d[-2][-1]-a[d[-2][-1]])
%o else: d[-1].append(d[-1][-1]-a[d[-1][-1]])
%o r=1
%o if r==0: d.pop()
%o r,g=0,0
%o a.append(v)
%o n+=1
%o if mode==0: print(n+1,a[n])
%o if mode>0:
%o u,q=0,[]
%o while u<len(o):
%o q.append(a[o[u]])
%o u+=1
%o print(n+1,a[n],q,o)
%o return a
%Y Cf. A360593.
%K nonn
%O 1,2
%A _S. Brunner_, Feb 14 2023