ABC 336
ABC 336
Problem
C
You can
only allow integers [0,2,4,6,8] That is
5 integers. If you write down the
example 0,2,4,6,8,20,22,24,26,28,40.
You can
realize that you can basically convert an integer to it's base 5
representation. For example
0 is 0
1 is 1
2 is 2
3 is 3
4 is 4
5 is 10
=> 20
6 is 11
=> 22
10 is 20
=> 40
That is the
translation into a base 5 representation gives the corresponding index into the
5 integers that are being used.
Problem
D
Nice
dynamic programming practice problem.
The idea is
to calculate the largest the peak you can get from scanning backwards
initially. You know that the next peak
can only be one greater than the previous peak.
So you just add one and take the min with the actual array value.
Then you
need to move in the forward direction and pick only the ones that work, which
are the min of the peaks from the forward and backward direction.
Problem
E
- Fix the digit
sum at most there is 1 to 126 for the digit sum
- Up to some
integer you want to find how many good integers there are, where a good
integer just means the integer is divisible by the sum of digits.
- Now if you fix
the digit sum can you solve it that way.
So now I'm only considering integers that have digit sum equal to
some fixed s value.
- Then for each
integer you only have to store what that integers remainder is when
divided by s. And then at the end
you will include in your answers for the solutions that contain a total
digit sum equal to s and those with remainder = 0.
In other
words you simplify the problem. You say
can I solve this for a specific digit sum s.
And you can
if you keep track of the states in the bag (digit sum, remainder modulo s,
tight)
new_remainder
= (remainder * 10 + dig) % s
Problem
F
not solved
Problem
G
not solved
Comments
Post a Comment