zapdospops's blog

By zapdospops, history, 5 years ago, In English

1195C - Basketball Exercise

idea:zapdospops,KA_Rma submission 62187241

This is a standard dynamic programming problem

There are always 2 rows and in each row n students. The abstract idea of this problem is the zig-zag adding. Now there will be some case to skip the place in zig-zag and jump to another row. Pretty sure this will be an well optimized brute force method.

DYNAMIC PROGRAMMING:(Maximization Problem)

Lets take the 2 input arrays as a and b. Here we can construct an DP array (list(list)) of size (n+2) .Then now the same zig-zag with special DP condition is carried out. Variable i starts form 2 to n+2. For every DP[0][i] we we take max(DP[1][i-1],DP[1][i-2]) and add the current array value that is a[i-2] and simultaneously for every DP[1][i] we take max(DP[0][i-1],DP[0][i-2]) +b[i-2]. If you visualize each step with this equation we get an idea how the dynamic program store and use the previously stored values. pic2 DP[1][i] and DP[0][i]  pic

refer this easy dp problem for better understanding house-rober-leetcode.

  • Vote: I like it
  • +1
  • Vote: I do not like it

»
5 years ago, # |
  Vote: I like it +11 Vote: I do not like it

Everything's alright, but, why make an editorial for the easiest dp problem ever?

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Lolololol, lmao, it even took two of you to come up with the idea. I thought i had seen it all but this beats me.