• <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)
            无码AV波多野结衣久久| AAA级久久久精品无码片| 情人伊人久久综合亚洲| 国产亚洲精久久久久久无码AV| 久久精品夜色噜噜亚洲A∨| 日日噜噜夜夜狠狠久久丁香五月| 91久久精品国产免费直播| 国产精品久久久久久五月尺| 久久精品国产亚洲网站| 少妇久久久久久久久久| 色综合久久久久网| 久久久久久精品无码人妻| 久久久久九九精品影院| 国产成人久久AV免费| 四虎亚洲国产成人久久精品| 亚洲国产二区三区久久| 亚洲国产精品无码久久一区二区| 久久免费高清视频| 久久夜色精品国产网站| 中文精品99久久国产| 亚洲日本久久久午夜精品| 开心久久婷婷综合中文字幕| 久久九九久精品国产| 久久国产高潮流白浆免费观看| 人妻精品久久久久中文字幕69| 亚洲国产成人久久综合一区77| 99久久人人爽亚洲精品美女| 久久国产欧美日韩精品| 久久久精品国产sm调教网站| 久久亚洲日韩看片无码| 久久精品国产男包| 精品久久久久久国产| 久久精品国产清自在天天线| 亚洲国产精品无码久久久不卡| 国产精品99久久久精品无码| 无码人妻久久一区二区三区蜜桃| 久久精品国产精品亚洲| 久久综合伊人77777| 99久久99久久精品国产片果冻| 蜜臀av性久久久久蜜臀aⅴ| 一本一本久久aa综合精品 |