We will hold AtCoder Beginner Contest 145.

- Contest URL: https://atcoder.jp/contests/abc145
- Start Time: http://www.timeanddate.com/worldclock/fixedtime.html?iso=20191116T2100&p1=248
- Duration: 100 minutes
- Number of Tasks: 6
- Writer: kort0n, kyopro_friends, YoshikaMiyafuji
- Rated range: ~ 1999

The point values will be 100-200-300-400-500-600.

We are looking forward to your participation!

How To Solve 'E'?

It's a standard knapsack problem, the only difference being that the order you want to eat the food in is increasing by A (you want the longest food you'll eat to be at the end)

I still didn't get , why sorting with respect to time gives AC. Can you please,explain?

Because you want to eat a couple, and then the last one you eat can go over. Since it can go over and is not bounded by T, then the BEST one to go over is the largest one from the subset you selected.

Formally if you have a subset of times A1, A2, A3 ... Ak, you can eat them iff, you have a subset of k-1 that is <= (T-1). Now you see that you want to remove the maximum one from the subset. Sorting it and doing a knapsack will guarantee that the last one is the added is the maximum one in the subset

Let $$$dp[i][j]$$$ be maximal happiness you can achieve taking some of first i dishes during j minutes. Let $$$backdp[i][j]$$$ be maximal happiness you can achieve taking some of

lastdishes (with indices from i to n) during j minutes. Now let's go through the dish that we will eat last ($$$i$$$) and time we spent on eating first $$$i - 1$$$ dishes ($$$t'$$$). Try to update answer as $$$min(answer, dp[i - 1][t'] + backdp[i + 1][(t - 1) - t'] + b[i]$$$. It's easy to calc $$$dp$$$ : $$$dp[i][j] = max(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - a[i]] + b[i]$$$ (if such exist)$$$)$$$. Same with $$$backdp$$$.How to Solve D ?

If you print the matrix you notice that every third diagonal is part of pascals triangle (so just implement combinations and get the right row and column in the triangle)

Can you please detail more the idea and solution ?? Thanks

To get to x, y from 0, 0 we have to do some (i + 1, j + 2) and some (i + 2, j + 1) moves. So, let's iterate how many times we will do (i + 1, j + 2) moves and check whether if moves left can be done with some number of (i + 2, j + 1). If the total number of moves is N, and we did K (i + 1, j + 2) type moves, number of ways to do it will be $$$C_{N}^{K}$$$

But how to implement combinations.I think it can't work when using mod.This worries me so much.

You can calculate factorials modulo n, store them in fact[x]; And then inverse of factorials modulo N. (since MOD is prime, invFact[n] = POW(fact[n], MOD-2))

And since comb(a,b) = fact[a] / (fact[b] * fact[a-b]) modulo this means

fact[a] * invfact[a] * invfact[a-b].

Edit: Tutorial that explains https://www.geeksforgeeks.org/compute-ncr-p-set-3-using-fermat-little-theorem/

Thanx

You also can use Extended Euclidean to find modular inverse. I prefer it more than fermat.

link: You only need to read equations, so don't worry about language.

MatrixDPcoder rip rating

what's the dp at F? plase

best[i][j][k] -> best cost if you only consider the first i columns, the i-th column has value j and you've done k changes already. (j is really big, but you notice that there's no use in changing in something that's not already in the input, or 0). (Note, since you only look 1 in the past with i, you can only store 0/1 for it)

The big observation to make this fit in time is that if the previous one has height X, then if you change the current one, you don't want to make it shorter, since that won't decrease the cost, but might increase it in the future.

What is the after contest test case added for problem E All you can eat? My solution fails for it and passes the rest.