i am stuck with this dp problem , can any someone explain me the state of dp for this problem ? problem link is Question

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

1 | tourist | 3557 |

2 | Um_nik | 3494 |

3 | Radewoosh | 3344 |

4 | wxhtxdy | 3309 |

5 | LHiC | 3302 |

6 | Benq | 3286 |

7 | mnbvmar | 3274 |

8 | Petr | 3254 |

9 | yutaka1999 | 3190 |

10 | ksun48 | 3170 |

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

1 | Errichto | 191 |

2 | Radewoosh | 180 |

3 | PikMike | 165 |

3 | antontrygubO_o | 165 |

5 | Vovuh | 164 |

6 | rng_58 | 161 |

7 | tourist | 157 |

8 | majk | 156 |

8 | Um_nik | 156 |

10 | 300iq | 155 |

i am stuck with this dp problem , can any someone explain me the state of dp for this problem ? problem link is Question

↑

↓

Codeforces (c) Copyright 2010-2019 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Oct/15/2019 08:19:44 (f2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

This is a difficult DP problem until you know the trick. When would a triangle be invalid? Only when one of the side lengths is >= 1/2 of the total sum. With this in mind we can count how many assignments are invalid triangles, rather than how many assignments are valid triangles. This problem is significantly easier — we have 2 parts to our state: current sum and current item. At each spot we have 2 choices — add to our sum or don't. Succeed when our value reaches 1/2 of the total array sum. Total time is O(2 choices * 300 indexes * 300^2 max sum). We can recover the answer by taking 3^N — 3 * the result of our DP.

What about the difference property. Difference of 2 sides must be smaller than third

That should be covered by the same logic.

What you said isn't much clear. But I understood is by subset sum problem we can find the number of ways to make every sum. Then we can add the counts for the numbers greater than n/2 Is that right

If you have |A-C|>B and A+B+C=X then A or C must be >= X/2

Thanks bro. I got it now. The main point is if we handle the sum property for a triangle then the difference property is handled automatically, right?