Блог пользователя edem.kwadzo

Автор edem.kwadzo, 14 лет назад, По-английски

Hi Guys,
can anyone help me solve this problem using DP ? is that even possible ?

http://acm.timus.ru/problem.aspx?space=1&num=1005

So far only the brute force (generate all permutations) approach seems to be working.

Many thanks

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

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

Use bit-masks. Take a integer number and look at its bits. If i-bit is 1, then we put stone i+1 in first pile, else in second pile. You need check all numbers between 0 and 2^N - 1 (all possible variants of ones).
It's not DP, but it's fast brut force O (N * 2^N). Also this task can be solved by time O (N * 2^(N/2)) with method meet-in-middle.

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

For dp solution you can use idea of Knapsack problem.

dp[i][j] = true iff using some of i first stones we can get the pile of weight j.

14 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
This is classic problem, for the dynamical programming with using bimasks. A bit more difficult task when you have 34 stones
14 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
Тhis is a classic NP-complete problem. It is not about the dynamic programming.