Here you will find solutions of many problems on spoj. If you want solution of some problem which is not listed in blog or have doubt regarding any spoj problem (which i have solved) or any programming concept (data structure) you can mail me @
And my humble request to you all that don't copy the code only try to understand the logic and algorithm behind the code. I have started this because if you tried as hard as you can and still can't find any solution to the problem then you can refer to this.
You can read my answer how to start competitive programming CLICK HERE

Tuesday, December 30, 2014

NUMPLAY-Fun with numbers

Fun with numbers

given below python 2.7 code is for numplay spoj or fun with numbers.

This is an easy DP problem

import sys
arr = []
def pre():
    arr1 = []; arr3 = []; arr5 = []; arr7 = [];
    arr1.append(0), arr3.append(0), arr5.append(0), arr7.append(0)
    arr1.append(1), arr3.append(1), arr5.append(1), arr7.append(1)
    for i in range(2,10001):
        arr3.append(arr1[i-1] + arr7[i-1])
        arr5.append(arr3[i-1] + arr7[i-1])
        arr.append(arr1[i] + arr3[i] + arr5[i] + arr7[i])

t = int(sys.stdin.readline())
while t:
    n = int(sys.stdin.readline())
    print arr[n]
    t = t-1;