Computer Science Canada s5 2007 |
Author: | Integrate [ Thu Nov 01, 2007 6:48 pm ] | ||||
Post subject: | s5 2007 | ||||
Hello. I've been practicing with some competition questions and I am having some problems with doing s5 from the CCC competition 2007: http://compsci.ca/v3/viewtopic.php?t=15232 I've been trying to do the problem in turing, but my problem is that my answer is too slow. It works fine for smaller numbers and such, but as they start to get big, my program takes much longer to finish. I tried to solve the problem by trying to find all the possible arrangements of ways to hit the pins. I have tried to increase the speed by making the program not go over the same arrangement twice, but for a case of 50 pins with 8 balls of size 4, I'm exceeding 4x10^13 arrangements. I would like to know if there is a better way to do this (on turing), or if I am doing it wrong. Here is my code (sorry, its uncommented since I was timing myself, plus I was using bits of code from s1 to s4 so some useless artifacts might be in there), the test data I'm having problems with, and the answers to the data. I decide to output my data onto the screen because it was easier for me to check the answers.
test data: save as s5.in
answers to that set of data: 51755 107873 197422 Thanks for your time! |
Author: | Tony [ Thu Nov 01, 2007 8:12 pm ] |
Post subject: | RE:s5 2007 |
umm.. Quote: for h : 1 .. upper (scorearray) maxscore := max (scorearray (h), maxscore) end for You're calculating every possible score in there? It's Pins nCr Balls combinations. Assuming Pins >>> Balls: (Pins - Balls)^Balls will give you a conservative estimate of the value. So it could be over 29500^500. That's a lot. So it should be clear that you're not supposed to try everything. -------- A hint comes in a form of Bob's strategy for going after the highest scoring shot, one at a time. That's very easy to do, even in O(N^2) sort, 30,000^2 is <<< 29500^500. Supposedly this will give you the correct answer 20% of the time, and be fairly close the rest of the time. This should be your starting case, not 0. I think that checking if any particular shot will improve/worsen Bob's strategy on the remainder, should give you the answer in O(N^3) time. |