Formula One Strategist
JavaScript (ES6), 234 bytes
Takes input as (track)(laps)
, where track
is an array of characters. Returns a string with \$0\$ = soft, \$1\$ = medium, \$2\$ = hard.
a=>k=>(a.map(c=>(C++,d+=P,c=='P'|c=='#'?P^=350:t+=p!=(p=c)),p=a[1],P=d=C=t=0),m=g=(n,L=k,x=0,o='')=>L?g(n>>2,L-=j=(j=1e5/(C*[15,10,8][n&=3]+t*[263,161,128][n]))>L?L:j|0,x-j*t*!!n*~n*3+d,o+n):(m=m<x|m==x&o>P?m:(P=o,x),n?P:g(++N)))(N=0)
Try it online!