• <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久久做夜夜爱天天做精品| 国产99久久九九精品无码| 久久精品国产99国产精品亚洲| 狠狠色丁香婷婷久久综合五月| 久久精品国产亚洲精品2020| 欧美一区二区精品久久| 麻豆久久| 青青草国产精品久久久久| 久久人人爽人人爽人人片av麻烦| 久久精品国产亚洲沈樵| 久久人人爽人人人人爽AV| 亚洲国产精品人久久| 亚洲va久久久噜噜噜久久| 久久无码精品一区二区三区| 狠色狠色狠狠色综合久久| 中文国产成人精品久久不卡| 日韩十八禁一区二区久久| 久久精品国产只有精品2020| 中文字幕日本人妻久久久免费 | 精品国产日韩久久亚洲| 久久精品一区二区国产| 人妻精品久久久久中文字幕一冢本| 久久久久人妻一区精品| 四虎国产精品免费久久5151 | 国产激情久久久久影院小草| 久久天天躁狠狠躁夜夜网站| 久久亚洲中文字幕精品一区| 国产美女久久久| 国产精品99久久久精品无码| 久久性生大片免费观看性| 国产精品久久久久乳精品爆| 国产午夜久久影院| 伊人久久精品线影院| 99久久精品费精品国产一区二区| 亚洲精品无码久久千人斩| 99蜜桃臀久久久欧美精品网站| 久久毛片一区二区| 亚洲综合熟女久久久30p| 久久精品无码专区免费东京热| 日本强好片久久久久久AAA| 久久香蕉国产线看观看精品yw|