Блог пользователя chokudai

Автор chokudai, история, 4 года назад, По-английски

We will hold AtCoder Beginner Contest 145.

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

We are looking forward to your participation!

  • Проголосовать: нравится
  • +28
  • Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

How To Solve 'E'?

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    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)

    • »
      »
      »
      4 года назад, # ^ |
      Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

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

      • »
        »
        »
        »
        4 года назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        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

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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 last dishes (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$$$.

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

How to Solve D ?

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    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)

    • »
      »
      »
      4 года назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

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

      • »
        »
        »
        »
        4 года назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        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}$$$

    • »
      »
      »
      4 года назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

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

    • »
      »
      »
      4 года назад, # ^ |
        Проголосовать: нравится +1 Проголосовать: не нравится
      Matrix
»
4 года назад, # |
Rev. 2   Проголосовать: нравится +13 Проголосовать: не нравится

DPcoder rip rating

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

what's the dp at F? plase

  • »
    »
    4 года назад, # ^ |
    Rev. 2   Проголосовать: нравится +6 Проголосовать: не нравится

    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.

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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