• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Uriel's Corner

            Research Associate @ Harvard University / Research Interests: Computer Vision, Biomedical Image Analysis, Machine Learning
            posts - 0, comments - 50, trackbacks - 0, articles - 594
            Given the age and score of each players. Selected some of them to obtain the maximum total score and make sure that all the selected players with a younger age do not have a higher score than older ones (could be the same score).

            Two ways to do DP
            Approach 1: zip the age and score of each player, sort by score, then go through all the players' age and sco, update dp matrix as:
            dp[age] = max(dp[:age+1]) + sco
            return max(dp)

            Approach 2: zip the age and score of each player, sort by age, then go through all the players i, update dp matrix as:
            dp[i] = max(dp[i], dp[j] + scores_sorted_by_age[i][1]), while j < i and scores_sorted_by_age[j][1] <= scores_sorted_by_age[i][1]:
            return max(dp)

            - Time complexity:
            Both methods are O(n^2)
            - Space complexity:
            Both methods are O(n)


            Approach 1:

             1 #1626
             2 #Runtime: 285 ms (Beats 100%)
             3 #Memory 13.8 MB (Beats 80%)
             4 
             5 class Solution(object):
             6     def bestTeamScore(self, scores, ages):
             7         """
             8         :type scores: List[int]
             9         :type ages: List[int]
            10         :rtype: int
            11         """
            12         dp = [0] * (max(ages) + 1)
            13         scores_sorted_by_scores = sorted(zip(scores, ages))
            14         for sco, age in scores_sorted_by_scores:
            15             dp[age] = max(dp[:age+1]) + sco
            16         return max(dp)


            Approach 2:

             1 #1626
             2 #Runtime: 1532 ms (Beats 55%)
             3 #Memory: 13.9 MB (Beats 65%)
             4 
             5 class Solution(object):
             6     def bestTeamScore(self, scores, ages):
             7         """
             8         :type scores: List[int]
             9         :type ages: List[int]
            10         :rtype: int
            11         """
            12         dp = [0] * len(ages)
            13         scores_sorted_by_age = sorted(zip(ages, scores))
            14         for i in range(len(ages)):
            15             dp[i] = scores_sorted_by_age[i][1]
            16             for j in range(i):
            17                 if scores_sorted_by_age[j][1] <= scores_sorted_by_age[i][1]:
            18                     dp[i] = max(dp[i], dp[j] + scores_sorted_by_age[i][1])
            19         return max(dp)
            久久久一本精品99久久精品66 | 久久久久亚洲AV成人网| 777米奇久久最新地址| 中文字幕成人精品久久不卡| 欧美激情精品久久久久久久| 久久99热这里只频精品6| 奇米综合四色77777久久| 国内精品久久久久久久久电影网| 国产精品免费看久久久| 久久综合视频网| 精品久久久久久无码人妻热| 7777精品伊人久久久大香线蕉| 99久久国语露脸精品国产| 人妻丰满?V无码久久不卡| 久久97久久97精品免视看| 久久亚洲日韩看片无码| 91麻豆精品国产91久久久久久| 精品久久久久成人码免费动漫 | 久久亚洲电影| 9久久9久久精品| 久久人人爽人人爽人人爽| 欧美精品一区二区久久| 国产精品视频久久| 日韩人妻无码一区二区三区久久 | 色综合久久久久综合体桃花网| 久久九九免费高清视频| 2020最新久久久视精品爱 | 久久亚洲精品人成综合网| 尹人香蕉久久99天天拍| 久久久受www免费人成| 色综合久久中文综合网| 久久国产精品视频| 岛国搬运www久久| 久久久久亚洲精品无码网址| 久久亚洲精品中文字幕三区| 成人免费网站久久久| 精品国产福利久久久| 亚洲精品NV久久久久久久久久| 久久久亚洲精品蜜桃臀| 色天使久久综合网天天| 亚洲国产精品无码久久98|