ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1005. Stone Pile

method of decision
Posted by Vitaliy_Ivashchenko 29 Aug 2007 21:58
In this problem only there are only 20 stones(elements). So we can generate all possible variants of rearrange the stones into two piles. There will be 1,048,576 variants for 20 stones. Realization of such algorithm will work about 1 second(less than Time limit - 2 seconds). But I meet alike problem where can be about 60 elements. And in such case count of varians will decrease to 1,152,921,504,606,846,976. As you understand time limit in such way will be exeeded. I think than we have to use dinamic programming. Can anybody tell how to solve this problem with dinamic programming?
Re: method of decision
Posted by AlainDelon 8 Dec 2007 15:08
for DP method, the optimal result is just a pile with the closet weight to half of all the stones.

suppose use a function named "getmid(beg,mid)" to find the most closet pile's weight when given two parameters ("beg", and "mid"). "beg" means the start index of stone in the left stone collection, "mid" means the perfect half value(you try to reach). the formula is as below:

|- If mid <= 0 Then getmid(beg, mid) = 0;
|
|- If mid < Weight[beg] Then getmid(beg, mid) = getmid(beg+1, mid)
|
|- If mid >= Weight[beg] Then getmid(beg, mid) = MaxOptimal[ Weight[beg] + getmid(beg+1, mid-Weight[beg]), 0+ getmid(beg+1, mid ]
Re: method of decision
Posted by [SESC USU] Efanov N. 27 Mar 2010 18:45
I have generated all possible variants, and I have not got TL. AC in 0,296 seconds. But I think DP is better)
Re: method of decision
Posted by хус 7 Oct 2010 18:58
acmp.ru AC
acm.timus.ru WA2
Can you help me?
I have generated all possible variants
may be something wrong?
(Binar Sistem of Counting)

Edited by author 07.10.2010 19:50

Edited by author 07.10.2010 19:51
Re: method of decision
Posted by Andri 9 Oct 2010 14:55
This problem so decides; sorts stones, then looking for the difference modulo!