You missed RRRR. It is not necessary for white flower to be present.
It should be j<5. also you don't need to use long long in this case. int would be fine.
Also I found a weird problem in your code. None of your if else condition is working!!
you can check it by giving some input..
I read that we should use strcomp instead of equality when comparing strings..still trying to figure out why to do so.
for the first value of q(1,1) state of the bear at 1,1 changed from 0 to 1, so the new score will be 3(earlier it was 2).Again for the second value of q(1,4) state changed from 0 to 1 so the new score will be 4(just before it was 3).
and so on..