|
|
вернуться в форум>I think only search is okey. >I think only search is okey. ur solution is not good. the better way is use remainder(mod) I wanna offer my solution (I think, author had in view same method). Arrange digits of the number in a such way: (non-zero digits in arbitrary order)1234(all zeroes). Then, we can permute only 1234 among them in order to receive a number, dividing by 7 (You can prove it). Edited by author 12.04.2005 01:20 Is anybody willing to tell me why it works? @Nickolas > Is anybody willing to tell me why it works? You can write a sample program and see, that permutations of 1234 produce all possible remainders in division by 7. So <some non-zero numbers><permutation on 1234><zeros> always fits. I wanna offer my solution (I think, author had in view same method). Arrange digits of the number in a such way: (non-zero digits in arbitrary order)1234(all zeroes). Then, we can permute only 1234 among them in order to receive a number, dividing by 7 (You can prove it). Edited by author 12.04.2005 01:20 No sorting, just "cutting" one : 1,2,3,4 from input number; selecting zeros and constructing "possible answer" :) cant we use dynamic programming.It is a O(2^numberofdigits) algorithm. Can any one tell me why the other solution works? |
|
|