30C - Shooting Gallery - CodeForces Solution


dp probabilities *1800

Please click on ads to support us..

Python Code:

import sys
from types import GeneratorType

input = lambda: sys.stdin.buffer.readline().decode().rstrip()


def bootstrap(f):  
    stack = []
    def wrappedfunc(*args, **kwargs):
        if stack:
            return f(*args, **kwargs)
        else:
            to = f(*args, **kwargs)
            while True:
                if type(to) is GeneratorType:
                    stack.append(to)
                    to = next(to)
                else:
                    stack.pop()
                    if not stack:
                        break
                    to = stack[-1].send(to)
            return to
    return wrappedfunc

mod = 10**9 + 7
def f(i,j) : 
    if i == n :
        return 0 
    if dp[i][j] != -1:
        return dp[i][j]
    res = f(i+1,j) 
    if (arr[i][0] - arr[j][0])**2 + (arr[i][1] - arr[j][1])**2 <= (arr[i][2] - arr[j][2])**2 or j == -1 : 
                res = max(res, (arr[i][-1] + f(i+1,i) ))
    dp[i][j] = res
    return res

def solve():
    global n,arr,dp  
    dp = [[-1 for _ in range(1001)] for j in range(1001)]
    n = int(input())
    arr = []
    for _ in range(n) :
        arr.append( list(map(float,input().split())) )
    arr.sort( key = lambda x : x[2])
        print(f(0,-1))


 
    solve()


Comments

Submit
0 Comments
More Questions

1585C - Minimize Distance
1506E - Restoring the Permutation
1539A - Contest Start
363D - Renting Bikes
1198D - Rectangle Painting 1
1023B - Pair of Toys
1725A - Accumulation of Dominoes
1675E - Replace With the Previous Minimize
839A - Arya and Bran
16B - Burglar and Matches
1625B - Elementary Particles
1725G - Garage
1725B - Basketball Together
735A - Ostap and Grasshopper
1183B - Equalize Prices
1481A - Space Navigation
1437B - Reverse Binary Strings
1362B - Johnny and His Hobbies
1299A - Anu Has a Function
1111A - Superhero Transformation
954A - Diagonal Walking
39F - Pacifist frogs
1451C - String Equality
386A - Second-Price Auction
1690E - Price Maximization
282B - Painting Eggs
440A - Forgotten Episode
233B - Non-square Equation
628B - New Skateboard
262B - Roma and Changing Signs