This problem easy to solve with DP(+)
Just use DP, which is fast enough (AC 0.187s),
and works without using long arithmetics in O(30*n).
Only remember simple math theorems about mod, i. e.
(a+b) mod c = ((a mod c) + (b mod c)) mod c
(a-b) mod c = ((a mod c) - (b mod c)) mod c
(a*b) mod c = ((a mod c) * (b mod c)) mod c
Re: This problem easy to solve with DP(+)
My brute-force solution got AC in 0.062s
Re: This problem easy to solve with DP(+)
Brute force without big numbers?
I think that the most easy solution is that,
where long arithmetics not used.
Re: This problem easy to solve with DP(+)
Послано
AlMag 11 авг 2008 23:06
DP here? How?
Re: This problem easy to solve with DP(+)
Послано
AlMag 11 авг 2008 23:29
Oh, i've got...
Let's see...
Re: This problem easy to solve with DP(+)
Послано
AlMag 12 авг 2008 00:58
No, i have too slow AC :( 1.531
Can anyone explain DP?
Re: This problem easy to solve with DP(+)
simple O(N) solution, 0.030s
You are completely right about using:
> (a*b) mod c = ((a mod c) * (b mod c)) mod c
Uses very facile DP technique like used[i] = true/false ;-)
Re: This problem easy to solve with DP(+)
You can achieve O(N) using bfs.
Edited by author 23.06.2009 21:23
Re: This problem easy to solve with DP(+)
DP here? How?
it`s knapsack problem
Re: This problem easy to solve with DP(+)
Послано
AleZan 8 дек 2011 15:33
please can anyone tell me how to solve this in briefly by bfs or dp......
Re: This problem easy to solve with DP(+)
I try DP but TLE #15, can send me your solution to my email : tungnk1993@gmail.com Tks
Re: This problem easy to solve with DP(+)
Послано
Ximera 11 мар 2013 00:13
I think it's nearer to bfs then DP