@@ -584,3 +584,62 @@ def closestTarget(self, words: List[str], target: str, startIndex: int) -> int:
584584 minnum = min (minnum , dist )
585585
586586 return - 1 if minnum == float ("inf" ) else minnum
587+
588+ def countUnguarded (self , m : int , n : int , guards : List [List [int ]], walls : List [List [int ]]) -> int :
589+ record = [[0 for _ in range (n )]for _ in range (m )]
590+
591+ def guard_dfs (x , y ):
592+ for temp_y in range (y + 1 , n , 1 ):
593+ #这个位置有守卫or墙就可以略过了
594+ if record [x ][temp_y ] == - 1 :
595+ break
596+ #这个位置在纵向上横着过去已经有守卫纵向盯着
597+ elif record [x ][temp_y ] == 2 or record [x ][temp_y ] == 3 :
598+ break
599+ #这个位置有人横向盯着
600+ elif record [x ][temp_y ] == 1 :
601+ record [x ][temp_y ] = 3
602+ else :
603+ record [x ][temp_y ] = 2
604+
605+ for w in walls :
606+ record [w [0 ]][w [1 ]] = - 1
607+ for g in guards :
608+ x = g [0 ]
609+ y = g [1 ]
610+ record [x ][y ] = - 1
611+ guard_dfs (x , y )
612+ ans = 0
613+ for i in range (m ):
614+ for j in range (n ):
615+ ans += 1 if record [i ][j ] == 0 else 0
616+ return ans
617+
618+ def mostPoints (self , questions : List [List [int ]]) -> int :
619+ n = len (questions )
620+ dp = [[0 , 0 ] for _ in range (n )]
621+ """
622+ dp[i][0]代表如果在i处于能解决问题的状态,所可以获得的最大分数
623+ dp[i][1]代表如果在i处于不能解决问题的状态,所可以获得的最大分数
624+ """
625+
626+ for idx , question in enumerate (questions ):
627+ if idx == 0 :
628+ dp [idx ][0 ] = 0
629+ dp [idx ][1 ] = question [0 ]
630+ else :
631+ dp [idx ][0 ] = max (dp [idx - 1 ][0 ], dp [idx ][0 ])
632+ dp [idx ][1 ] = max (dp [idx - 1 ][1 ], dp [idx ][0 ] + question [0 ])
633+
634+ next_res_idx = idx + question [1 ] + 1
635+ if next_res_idx < n :
636+ dp [next_res_idx ][0 ] = max (dp [next_res_idx ][0 ], dp [idx ][0 ] + question [0 ])
637+
638+
639+ return max (dp [- 1 ])
640+ # Your MovieRentingSystem object will be instantiated and called as such:
641+ # obj = MovieRentingSystem(n, entries)
642+ # param_1 = obj.search(movie)
643+ # obj.rent(shop,movie)
644+ # obj.drop(shop,movie)
645+ # param_4 = obj.report()
0 commit comments