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

Автор sugim48, 7 лет назад, По-английски

The contest was postponed to 2019-01-06(Sun) 11:00-16:00 UTC.

Hello, Codeforces!

We will hold Educational DP Contest at AtCoder on Saturday.

About the Contest

This is an unofficial contest to practice DP (Dynamic Programming). We selected 26 DPs, mostly basic ones, and prepared a problem to learn each of them. Test your skills during the real contest, and brush them up after it ends.

Details

Rules

The rules for ABC, ARC and AGC apply. The important points are:

  • This is an individual match; no teams allowed.
  • Revealing the solutions to others during the contest is prohibited.
  • The penalty for an incorrect submission is 5 minutes.

Notices

  • The problems may NOT be arranged in ascending order of difficulty.
  • There are many famous problems.
  • The contest is not intended for experts such as reds (anyone can compete, though).
  • It is recommended to use languages that are not too slow (such as C++ and Java).

Staff

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

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +16 Проголосовать: не нравится

Nice idea

»
7 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +44 Проголосовать: не нравится

the problems with u all setters are that for u even div1 e problems are easy ..

so cant guess what easy means here

»
7 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +41 Проголосовать: не нравится

So which level are the problems in? Will the problem set be interesting for orange coders? and purple?

Since you say they are basic ones, it sounds like it should be somehow like div2 contests?

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +78 Проголосовать: не нравится

Neat idea! Are there any plans to do this with other topics as well (e.g. Educational Combinatorics contest, educational geometry contest, etc.)? I think that could be really beneficial for a lot of people, especially if this contest goes well.

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +31 Проголосовать: не нравится

Very nice initiative

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +32 Проголосовать: не нравится

Now this is some serious effort by Atcoder this year to help us strengthen up our DP. Hope they continue to come up with such good ideas.

»
7 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +22 Проголосовать: не нравится

I wanted something like this

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +40 Проголосовать: не нравится

Will an english editorial be posted when the contest ends ?

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +23 Проголосовать: не нравится

Why is the contest postponed?

  • »
    »
    7 лет назад, скрыть # ^ |
    Rev. 9  
    Проголосовать: нравится +13 Проголосовать: не нравится

    As mentioned in the sugim's tweet on twitter it is due to the codeforces round clashing with the atcoders' round.

    "1/5 (土) 20:00 — 25:00 に開催予定の DP まとめコンテスト (https://atcoder.jp/contests/dp ) ですが、1/5 (土) 25:30 — に Codeforces のコンテストが生えたので、1/6 (日) 20:00 — 25:00 への移動を検討しています。ぜひアンケートにご協力ください。"

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +17 Проголосовать: не нравится

Nice idea to test how good you are in dp :DDD

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

Reminder: The contest starts in an hour.

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +14 Проголосовать: не нравится

Are questions sorted by difficulty?

and thanks for this ^^

»
7 лет назад, скрыть # |
Rev. 3  
Проголосовать: нравится +14 Проголосовать: не нравится

How to solve Permutations in less than n3 ?

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +33 Проголосовать: не нравится

Thanks very much for contest ! When editorial will be available ?

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +14 Проголосовать: не нравится

How to solve 0-1 Knapsack with weights <= 1e9?

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +14 Проголосовать: не нравится

The contest was very nice, i didn't manage to solve quite a few problems(i got 18), which is a good thing since i will be able to solve them now and learn new things :).

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

How to solve Sushi?

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

What is testcase 1_03 for E?

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +9 Проголосовать: не нравится

In Matching I had O(n2 * 2n ) solution, how to optimize it? I feel really stupid

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +20 Проголосовать: не нравится

I hope this is the first of many Educational Rounds to come from AtCoder. Looking forward to more such good content.

Here are my solutions to the problems of this contest, in case anybody wants to refer.

»
7 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +5 Проголосовать: не нравится

Is CHT of Z really easier than rerooting of V or inclusion-exclusion thingy of Y?) Or is there any solution without CHT?

Btw, how does one generate tests for CHT dp? Like what stops me from maintaining MAGIC best by some parameter positions and trying to update from them all (like in O(n·MAGIC))?

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

Why is the limit of n so big in problem U? I spent 20 minutes trying to optimize it without realizing that O(2^32) will fit TL. Is there a faster solution?

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

Can someone explain the editorial of problem N,slimes?

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

How about the problem STONES

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

How to solve R-Walks?

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

    The TLE is caused by visiting a state over and over.

    Remember a node can have many parents.

    I suggest you count the answer for each node on a topdown manner , and when visiting it again just return its value.

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

Can someone explain why/how Convex Hull Trick is used for Z?

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +24 Проголосовать: не нравится

W is almost https://csacademy.com/contest/archive/task/popcorn without alien's trick (this problem is W but with positive weights and every position has an equal negative weight). I'll use this opportunity to ask: how to solve it faster than O(n * logn) with a lazy seg tree? Since O(N * log^2) is TLE for POPCORN.

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

Any hint on Problem R(Walks) if the constraints on N would have been higher ?
With given constraints on N, it could be easily solved using Matrix Exponentiation but what if constraints on N were higher.

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +13 Проголосовать: не нравится

Can someone tell me the solution for problem X-tower and W-Intervals? I can't figure out the solution for these problems during the contest.

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +35 Проголосовать: не нравится

will There be any Editorial??

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +98 Проголосовать: не нравится

I would like to request AtCoder to hold more such contests on various topics, such as one on range queries and updates, one on geometry, one on number theory and combinatorics, one on graphs, etc., similar to the dp one (where known methods are used in various ways to solve the problems).

I think this would be a great idea, helping many of us gaining the basics of topics quickly. Holding them at a every 10 days or so time interval would allow enough time to prepare the contest as well as give contestants time to upsolve the last one. I hope this is seriously considered!

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

How can i see testcases which my solution failed in this contest.

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

Thanks a lot to all the authors, the problems are really exciting.

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

Can anybody please explain the solution for problem Y — Grid 2 as well? I'm kinda stuck. :) Basically, on how to calculate the value of so many 's when both n and r can be upto 1e5?

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +14 Проголосовать: не нравится

How to solve V (Subtree)?

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

    Let's calculate two values for every node after rooting the tree:

    • down[node] = number of ways to paint the descendants of node when node is black

    • up[node] = number of ways to paint vertices not in the subtree of node when node is black

    The answer for any node is the product of these values, down[node] × up[node]

    down[node] is easier to calculate, it is (we let the subtree rooted at son all white or we have down[son] ways). The base case is when the node is a leaf, we have 1 way to color it black.

    up[node] is almost the same, (the 1 summing in the beginning comes from letting the parent white).

    The trick part with up is that the modulus will not always be co-prime with the values we got (so we won't be able to calculate the inverse modular by, let's say, maintaining the product of all sons and dividing by the current son down value to get the up[node] fast). The solution is to keep a prefix and suffix product of the down values for the sons of a node, this way we don't have to divide or use modular inverses.

    • »
      »
      »
      6 лет назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится
      //This code is solely the property of StarnyC
      #include<bits/stdc++.h>
      using namespace std;
      #define ll          long long
      #define int         long long
      #define pii         pair<ll,ll>
      #define Go_Baby_Go  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0);
      #define endl		'\n'
      
      int ans[100005],m;
      vector <int> adj[100005];
      map <pii , int> dp;
      
      int dfs(int par, int child)
      {
      	if( dp[ {par, child} ]  ) 
      		return dp[ {par, child} ];
      	
      
      	int temp = 1;
      	for(auto i:adj[child]) {
      		if(i==par) continue;
      		else { temp *= dfs(child, i) ; temp %= m; }
      	}
      
      	temp++;
      	dp[ {par, child} ] = temp;
      	return temp%m;
      }
      
      int32_t main()
      {  
      	Go_Baby_Go
      	int n;
      	cin >> n >> m;
      	for(int i = 0; i < n-1 ; i++) {
      		int x , y;
      		cin >> x >> y;
      		adj[x].push_back(y);
      		adj[y].push_back(x);
      	}
      
      	for(int i = 1; i <= n; i++) {
      		ans[i] = 1;
      		for(auto j:adj[i]) {
      			ans[i] *= dfs(i,j);
      			ans[i] %= m;
      		}
      		cout << ans[i] <<endl;
      	}
      
      }
       
      

      I am not able to figure out why this gives TLE although is running correctly for small test cases, one can guess the complexity of the above code is of order O((V+E)*log(V+E)) as the given graph is a tree , which fits in the constraints for the problem. Can you help me out?

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

        one can guess the complexity of the above code is of order O((V+E)*log(V+E)) as the given graph is a tree

        I am not sure this is true, for every edge you call DFS and inside the DFS you loop through every edge

        for(auto i:adj[child]) {

        I've put my code for reference of the above explanation

        Spoiler
»
7 лет назад, скрыть # |
 
Проголосовать: нравится +12 Проголосовать: не нравится

Hello, everyone. Someone could explain to me how to make the problem Z — Frog 3 into something better than O (n ^ 2). Greetings and thanks in advance.

»
7 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +10 Проголосовать: не нравится

Is there a clean way to implement the solution for U? My solution used approx. operations, which is about 4e8 when n = 16 and ran in 1.9s ( https://atcoder.jp/contests/dp/submissions/3969569 ), but I was curious if you could kick out that k factor from the sum and just get operations, which is like 4e7 on n = 16 and is much nicer.

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

So i just watched the new episode of Algorithms live where he and his guest talked about an O(n) solution to the problem L-Deque from the dp contest. I found this very interesting and implemented it. In fact, i found it so interesting that im writing this comment to let you all know about it :)

»
7 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +13 Проголосовать: не нравится

In Matching, I failed only at one test. I could not find bug in my code. Can anyone have a look? Thanks. My submission.

Edit: I fixed it. My above code fails for the test "1 1".

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

does there exists better solution for O-Matching than O(2n * n2), or it was intended to pass recursive solutions, while failing iterative?

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

    We can solve in O(2n * n) iteratively as well. We don't need the second dimension. Let k be the number of 'on' bits in the mask. dp[mask] represents number of ways in which first k men can pair with any k women subject to their preferences being matched. We can derive answer for current mask by turning off singular bits from the mask and checking compatibility of the k'th man being placed at this position.

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

Can someone explain the states and transitions of dp in problem T-Permutation. It got me thinking for a while now, and still don't get it. thanks in advance

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

Nice problems. Anyway how to solve C (vacation)?

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

Can anyone explain any other approach to solving S-Digit Sum, apart from digit dp, well I'm getting a MLE by the digit-dp approach!

Or can you provide an optimization to solve my error!

My submission

Thanks in advance!

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

    you got RE(Runtime Error) not MLE(Memory Limit Exceeded)

    Try again fixing these:

    1. the maximum value of your num.length() can be 10001, not 1005
    2. now if you think, you'll get your state sum is not good enough to be a DP state here as it can be big(<=9*10000) As we just only need to check "The sum of the digits in base ten is a multiple of D", instead of exact sum we can consider a state sum modulo D.
    3. in line 100 you are going to start working with index 0, how you are considering start as 1? Think again.
»
7 лет назад, скрыть # |
 
Проголосовать: нравится +13 Проголосовать: не нравится

How to solve M — Candies?

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

Can anyone explain how to do O-Matching problem?

Elaborate The dp states plzz!!

  • »
    »
    7 лет назад, скрыть # ^ |
    Rev. 5  
    Проголосовать: нравится +11 Проголосовать: не нравится

    F(mask) = number of ways to match all girls with 1-bit in mask with first P boys (P = number of 1-bit in mask)

    Answer is: F(1111) — full mask

    Transition:

    F(mask) = SUM( F(submask) )

    Where submask all subsets of mask without only one 1-bit (if it is possible to marrige P-th boy with this girsl)

    For example:
    F(1011) =

    if it is possible to marrige 3-d boy with 1-st girl
    F(1010) +

    if it is possible to marrige 3-d boy with 2-nd girl
    F(1001) +

    if it is possible to marrige 3-d boy with 4-th girl
    F(0011)

    We try to match P-th boy to every available girl (1-bit is a free girl)

»
7 лет назад, скрыть # |
Rev. 3  
Проголосовать: нравится +10 Проголосовать: не нравится

Why this O(MAX_DIGIT_LENGTH * D) solution timed-out for S-Digit Sum given that MAX_DIGIT_LENGTH<=10000 and D<=100 .

UPD: Got it. :) Passing string to the function caused TLE.

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

Can someone elaborate how to solve Problem W — Intervals?

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +13 Проголосовать: не нравится

How to solve G?

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

Can anyone please explain how to solve problem-W Intervals? It's been too long and i ain't able to solve it. Thanks

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

Can anyone help me with problem K? I have about 4 5 WAs. What's wrong with this approach?

const int max_n=110, max_k=100010, first=0, second=1;

int n, k, a[max_n], dp[max_k];

int f(int cnt){
    if(cnt <= 0) return false;
    if(dp[cnt]!=-1){
        return dp[cnt];
    }

    int res = f(cnt-a[0]);

    forup(i,1,n){
        res = res && (f(cnt-a[i]));
    }
    return dp[cnt]=(!res);
}

int main() {
    int mn = inf;
    gi(n);gi(k);
    memset(dp,-1,sizeof dp);
    rep(i,n){
        gl(a[i]);
        mn = min(a[i], mn);
    }
    rep(i,n){
        dp[a[i]] = true;
    }
    rep(i,mn){
        dp[i]= false;
    }
    f(k);
    cout << (f(k)?"First":"Second") << endl;
    return 0;
}
»
7 лет назад, скрыть # |
 
Проголосовать: нравится +11 Проголосовать: не нравится

someone explain the working of segment tree in Question W. Intervals.

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

Can anyone tell the idea for R-walk?

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +9 Проголосовать: не нравится

Why O(nk) is giving TLE verdict for (M)Candies. https://atcoder.jp/contests/dp/submissions/4245869

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +9 Проголосовать: не нравится

how to S?

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +11 Проголосовать: не нравится

Is it possible to see test cases. I keep getting WA for last 2 cases for Digit-Sum. https://atcoder.jp/contests/dp/submissions/4247905

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

What is the intuition behind problem I. Coins?

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

    On each coin, it can either come up heads or tails with certain probabilities. Make your dp state as dp[i][j] = probability of getting exactly j heads with the first i coin. Then, dp[i+1][j] will depend on dp[i][j] if we don't get heads with the i+1'th coin, or it will depend on dp[i][j-1] if we do get heads with the i+1'th coin.

    Prefix dp (i.e. memoizing with the first i elements) is extremely common and probably is applied for more than half (maybe more than 3/4) of the problems in this contest. The idea of having the second dimension counting the number of heads: that's just something you would learn to see with practice.

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

N-Slimes i am trying to solve this question using greedy and my idea is to merge the segment based on the value of two adjacent elements sum
~~~~~
int n;
cin>>n; vector<ll> v;

for(int i=0;i<n;i++)
{
int x;cin>>x;
v.pb(x);
}
ll ans=0;
for(int i=0;i<n-1;i++)
{
int ind1=-1;int ind2=-1;
ll temp=inf;
for(int j=0;j<v.size()-1;j++)
{
if(v[j]+v[j+1]<temp)
{
temp=v[j]+v[j+1];
ind1=j;
ind2=j+1;
}
}

v[ind1]+=v[ind2];  
ans+=v[ind1];  
v.erase(v.begin()+ind2);

}

cout<<ans<<endl;
~~~~~ this giving WA on test 6. I know DP is the intended solution for this problem and i already solved it using DP but i can't form an edge case to convince myself that how greedy is false here, please help me to find a case where greedy fails.

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +42 Проголосовать: не нравится

I had a stream where I solved all 26 problems with explanation. You can watch it on my Youtube channel: link. There are timestamps for each problem in the pinned comment below the video.

»
7 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +13 Проголосовать: не нравится

sugim48 Any plans to have another educational on AtCoder. As you might have already realized, the DP has been a huge success. I think you (and other collaborators) may already be considering it, but I can't resist and any rough timeline will be helpful.

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +15 Проголосовать: не нравится

Hi guys, would you mind publishing the tests for the tasks?

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +16 Проголосовать: не нравится

Will there be such contests again? I know preparing and testing this lot problems requires hard work but with more people it's feasible in not much time :)

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

how to think this problem problem L, how to design a dp status, thanks in advance

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

    https://atcoder.jp/contests/dp/submissions/15499385 solution for L base cases if array is of size 1 ans is a[i]
    how to think -> try to make a recursive function which will take inputs as range of the array the function can be something like this

    int function(int l,int r){
    {
         if(l==r) return a[l];
         return max(a[l]-function(l+1,r),a[r]-function(l,r-1));
    } 
    

    then try to optimize it i used map but it doesn't work then, eventually i found dp status which was quite easy to find after this and got AC by iterative method

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

need help with my solution for question Q.Flowers. Used persistent segment tree to have time limit of nlogn, but it gives TLE. Is using keyword new so costly ? Can someone hep me optimise this code ?

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

    Similar to UVa 11790, LIS with value map

    $$$dp[h]$$$ := max value LIS ending at height $$$h$$$

    The key point which makes this problem solvable in $$$O(NlogN)$$$ is that heights are distinct, In the $$$O(N^2)$$$ approach,

    //pseudo code
    for (int fl = 1; fl <= n; ++fl)
        for (int ht = 1; ht < height[fl]; ++ht)
           dp[height[fl]] = max(dp[height[fl]], dp[ht] + val[fl])
    

    the query of maximum is in a continuous range which should hint for using RMQ technique (like segment tree) So using segment tree we can have this in $$$O(NlogN)$$$

    //pseudo code
    for (int fl = 1; fl <= n; ++fl) 
      ll mx = queury(1, height[fl] - 1)
      dp[height[fl]] = max(dp[height[fl]], mx + val[fl])
      modify(height[fl], dp[height[fl]]) 
    
    

    Solution code

»
7 лет назад, скрыть # |
 
Проголосовать: нравится -8 Проголосовать: не нравится

How to solve U-Groupiing?

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

Can someone help me with the maths part in J sushi? I see the recurrence but am not very familiar with expected value so can someone elaborate it?

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

    Here is my attempt to explain the solution in the best possible manner. Hope this will help you and others as well :)

    First : what really matters is the number of dishes with 0, 1, 2 and 3 sushis and not the order of the dishes. So answer for 2,1,0,2,1 is same as answer for 0,1,1,2,2.

    Number of dishes with 0 sushis is easily determined by N — one — two — three, where one is the number of dishes with 1 sushi and N is the total number of dishes in the input.

    Let F(x, y, z) be the expected moves needed for x dishes with 1 sushi, y with 2 and z with 3.

    Now in the next move we can pick a dish with 1 sushi with a probability of x/N or p1. we can pick a dish with 2 sushi with a probability of y/N or p2. we can pick a dish with 3 sushi with a probability of z/N or p3. we can pick a dish with 0 sushi with a probability of (N — (x + y + z))/N or p0.

    Now try to understand this : F(x,y,z) = 1 + p0F(x,y,z) + p1F(x-1,y,z) + p2F(x+1,y-1,z) + p3F(x,y+1,z-1)

    Here we add a 1 for the current move that we are making. (Note : if you pick a dish with 3 sushi z decreases but y increases)

    This equation now becomes : (1 — p0) F(x,y,z) = 1 + p1F(x-1,y,z) + p2F(x+1,y-1,z) + p3*F(x,y+1,z-1)

    simplifies to: F(x,y,z) = (1 + p1F(x-1,y,z) + p2F(x+1,y-1,z) + p3*F(x,y+1,z-1))/(1-p0)

    This equation can be easily evaluated using dynamic programming :)
    However try and simplify the equation to minimize the number of divisions for higher precision.

    Implementation : https://atcoder.jp/contests/dp/submissions/9551520
    Let me know if you find something is not clear.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

I think it'll be a good idea to add the discuss button on top of this contest's page as well that links to this blog, just like other contests. It'll make the navigation easier for people trying to solve the problems to get to the discussion of solutions of the problems that are in this blog. I do think it's a very useful contest that people will be solving for a long time.

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

It's a shame that their is no editorial: the problems are quite educational. I think a major requirement for a contest to be educational is that it have a well-detailed editorial.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

Excellent learning series !!! Would be delighted if there is a similar series on Trees & Graphs and/or an advanced DP series...

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

It was a nice contest for learning and practicing DP.

»
3 года назад, скрыть # |
 
Проголосовать: нравится +2 Проголосовать: не нравится

where do i find the editorial to this contest problems??