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 @ raj.nishant360@gmail.com

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 = []
arr.append(0)
arr.append(4)
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):
        arr1.append(arr3[i-1])
        arr3.append(arr1[i-1] + arr7[i-1])
        arr5.append(arr3[i-1] + arr7[i-1])
        arr7.append(arr5[i-1])
        arr.append(arr1[i] + arr3[i] + arr5[i] + arr7[i])

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

No comments:

Post a Comment

Your comment is valuable to us