• <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)
            18岁日韩内射颜射午夜久久成人| 久久精品这里热有精品| 99久久精品免费观看国产| 久久精品亚洲日本波多野结衣 | 亚洲精品乱码久久久久久蜜桃| 国产精品九九九久久九九| 久久精品毛片免费观看| 久久久久无码精品国产| 久久成人国产精品| 青青草国产精品久久| 国产精品va久久久久久久| 香蕉久久一区二区不卡无毒影院 | 国产成人无码精品久久久久免费 | 久久精品国产亚洲网站| 国内精品久久久久久不卡影院 | 麻豆亚洲AV永久无码精品久久| 少妇久久久久久久久久| 久久精品中文闷骚内射| 久久精品国产影库免费看| 国产激情久久久久影院| 婷婷久久精品国产| 久久丫精品国产亚洲av不卡| 久久夜色tv网站| 亚洲AⅤ优女AV综合久久久| 日韩av无码久久精品免费| 狠狠久久亚洲欧美专区| 久久996热精品xxxx| 777午夜精品久久av蜜臀| 日本精品久久久久中文字幕| 亚洲国产精品无码久久青草| 久久国产精品无码HDAV| 久久国产精品视频| 久久久精品2019免费观看| 国产99久久久国产精免费| 久久久久人妻一区二区三区| 久久免费线看线看| 亚洲国产精品高清久久久| 久久福利片| 久久精品国内一区二区三区| 久久亚洲精品成人无码网站| 麻豆精品久久精品色综合|