First I am not very careful indeed.
p250 is easy, just recognize that you need to explore all possible states
dp[n][val], n is at most 50 and val is at most 1023
each (k, v) can lead to at most n new states.
For some reason I thought you only need dp[n], and the challenge follows.
p500 is not hard either. This is one of the few p500 problems that I got the idea pretty quickly. The reason I was not able to finish is:
1. I wrote too much python recently and keep using string str = "" + a[i] + tmp;
C++ does not understand what I am doing.
2. I didn't spend enough time to figure out the base case and my dp implementation is rather messy.
Given over 60min on p500 and I still could not get close enough to a working implementation. Quite disappointed with myself.
One more note, if you get SIGKILL in tc arena, you are using too much memory. string dp[55][55][55][55]; is too much, for example.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment