• <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久久综合国产精品二区| 久久精品国产WWW456C0M| 久久国产精品无码一区二区三区| 久久久久亚洲AV无码观看| 中文字幕乱码久久午夜| 欧美牲交A欧牲交aⅴ久久| 91精品国产高清久久久久久io| 99久久婷婷免费国产综合精品| 久久久久久综合一区中文字幕| 国产精品成人99久久久久91gav| 精品久久久久久无码中文字幕| 四虎影视久久久免费| 国产亚洲精品久久久久秋霞 | 精品久久久久久亚洲| 国产成人精品久久一区二区三区av| 久久久黄片| 久久久亚洲欧洲日产国码二区 | 久久婷婷五月综合97色直播| 亚洲精品无码久久千人斩| 久久精品成人国产午夜| 久久久久国产亚洲AV麻豆| 国内精品久久久久久久久电影网| 久久超乳爆乳中文字幕| 久久99亚洲综合精品首页| 久久人人爽人人爽人人片AV不| AV色综合久久天堂AV色综合在| 精品久久人人做人人爽综合| 久久人人爽人人爽人人片AV高清| 99久久久精品免费观看国产| 久久强奷乱码老熟女| 久久精品aⅴ无码中文字字幕重口| 国产精品九九久久免费视频| 久久久国产打桩机| 亚洲乱亚洲乱淫久久| 97精品依人久久久大香线蕉97 | 久久综合久久美利坚合众国| 九九99精品久久久久久| 久久综合偷偷噜噜噜色| 一本大道加勒比久久综合| 99蜜桃臀久久久欧美精品网站| 精品久久久久久国产牛牛app |