https://codeforces.com/contest/1882/problem/B

I tried so many times for solving this problem using DP. But it seems impossible. Can anyone help me?

# | User | Rating |
---|---|---|

1 | Radewoosh | 3759 |

2 | orzdevinwang | 3697 |

3 | jiangly | 3662 |

4 | Benq | 3644 |

5 | -0.5 | 3545 |

6 | ecnerwala | 3505 |

7 | tourist | 3486 |

8 | inaFSTream | 3478 |

9 | maroonrk | 3454 |

10 | Rebelz | 3415 |

# | User | Contrib. |
---|---|---|

1 | adamant | 173 |

2 | awoo | 167 |

3 | SecondThread | 163 |

4 | BledDest | 162 |

4 | Um_nik | 162 |

6 | maroonrk | 161 |

6 | nor | 161 |

8 | -is-this-fft- | 150 |

9 | Geothermal | 146 |

10 | TheScrasse | 143 |

https://codeforces.com/contest/1882/problem/B

I tried so many times for solving this problem using DP. But it seems impossible. Can anyone help me?

↑

↓

Codeforces (c) Copyright 2010-2023 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Dec/02/2023 11:52:48 (k1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

not possible with dp.

To anyone downvoting me. Solve the problem using dp and prove me wrong lol

I don't even know how to solve DP problems TT

There's a simple cubic-time solution: for each $$$x \in \bigcup_i S_i$$$ (i.e. each $$$x$$$ that occurs in at least one set), take the union of all sets that don't contain x. The answer is the size of the largest set you can create this way. If implemented in the obvious way, the time complexity is $$$\mathcal{O}\left(\left|\bigcup_i S_i\right| \cdot \sum_i \left| S_i\right|\right) = \mathcal{O}\left(n m^2\right)$$$, where $$$m$$$ is the maximum size of any input set.

I don't think it improves clarity in any way, but you can technically recast this algorithm in DP terms. Let $$$dp\left(i, x, y\right)$$$ be a Boolean value which is true iff one of the first $$$i$$$ input sets contains $$$y$$$ but not $$$x$$$. Then, $$$dp\left(0, x, y\right) = \text{False}$$$ and $$$dp\left(i + 1, x, y\right) = dp\left(i, x, y\right) \lor \left(x \not\in S_{i + 1} \land y \in S_{i + 1}\right)$$$.

Then, the answer is just the maximum number for any $$$x$$$ of $$$y$$$ values such that $$$dp\left(n, x, y\right)$$$ is true:

That said, I don't understand the point of trying to force this into being a "DP problem". The best technique to use is the simplest one that works, and thinking about this problem in DP terms doesn't seem to be the simplest way to approach it.

The trivial DP of trying all combinations of the said 50 sets will be too slow: O(2^50)

Skill Issue

I hope there is no need to solve a problem in a hard way like using DP. When you can solve this type of problem in an easy way. But trying problem in a new way is such a good thing for progress.