I have no idea, I find them really the same. I spent quite sometime debugging, but I can't reach anything.
Link to problem : http://www.spoj.com/problems/ACODE/
It's a dp problem.
Link to AC Solution ( C++ ): http://ideone.com/qYpw2x
Link to WA Solution (C++) : http://ideone.com/KxpmuI
If the code is not clear, or the logic. I can add more details.