updating delete and earn with python sol
This commit is contained in:
Binary file not shown.
@@ -5,6 +5,8 @@
|
||||
\usepackage{url}
|
||||
\pagenumbering{gobble}
|
||||
\usepackage{hyperref}
|
||||
\usepackage{graphicx}
|
||||
\input{statement/preamble.tex}
|
||||
|
||||
\title{ Tutorial: Análise de Dados}
|
||||
\author{Leetcode 1223}
|
||||
|
||||
Binary file not shown.
@@ -34,6 +34,7 @@ Em seguida, são dados seis inteiros \(d_1, d_2, d_3, d_4, d_5, d_6\), cada um r
|
||||
A saída consiste em um único inteiro representando o número total de sequências válidas de lançamentos, considerando o resultado módulo \(10^9 + 7\).
|
||||
|
||||
\ExemploEntrada
|
||||
|
||||
\begin{Exemplo}
|
||||
\texttt{2} & \texttt{34}\\
|
||||
\texttt{1~1~2~2~2~3} & \\
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
},
|
||||
"solutions": {
|
||||
"main-ac": "ac.cpp",
|
||||
"alternative-ac": [],
|
||||
"alternative-ac": ["test.py"],
|
||||
"wrong-answer": [],
|
||||
"time-limit": [],
|
||||
"time-limit-or-ac": [],
|
||||
|
||||
Binary file not shown.
@@ -5,6 +5,8 @@
|
||||
\usepackage{url}
|
||||
\pagenumbering{gobble}
|
||||
\usepackage{hyperref}
|
||||
\usepackage{graphicx}
|
||||
\input{statement/preamble.tex}
|
||||
|
||||
\title{ Tutorial: Deletar e Ganhar}
|
||||
\author{Leetcode 740}
|
||||
|
||||
Binary file not shown.
@@ -19,6 +19,7 @@ A segunda linha contém \( n \) inteiros \( a_1, a_2, \ldots, a_n \) (\( 1 \leq
|
||||
A saída deve conter um único inteiro, representando a pontuação máxima possível obtida após realizar as operações descritas.
|
||||
|
||||
\ExemploEntrada
|
||||
|
||||
\begin{Exemplo}
|
||||
\texttt{3} & \texttt{8}\\
|
||||
\texttt{3~4~5} & \\
|
||||
|
||||
@@ -36,14 +36,14 @@
|
||||
"run_specific_solution": "",
|
||||
"generate_io_only": false,
|
||||
"generate_pdf_only": false,
|
||||
"cpu_count": 1,
|
||||
"cpu_count": 0,
|
||||
"build_pdf": true,
|
||||
"pdf_format": "ds",
|
||||
"io_samples": 3
|
||||
},
|
||||
"solutions": {
|
||||
"main-ac": "ac.cpp",
|
||||
"alternative-ac": [],
|
||||
"alternative-ac": ["saad.py"],
|
||||
"wrong-answer": ["WA.cpp"],
|
||||
"time-limit": ["TLE.cpp"],
|
||||
"time-limit-or-ac": [],
|
||||
|
||||
36
delete-and-earn/src/saad.py
Normal file
36
delete-and-earn/src/saad.py
Normal file
@@ -0,0 +1,36 @@
|
||||
|
||||
class Solver:
|
||||
|
||||
def __init__(self):
|
||||
self.n_ = 0
|
||||
self.v_ = []
|
||||
self.freq_ = []
|
||||
|
||||
def read_input(self) -> None:
|
||||
self.n_ = int(input())
|
||||
self.v_ = list(map(int, input().split()))
|
||||
|
||||
def process_freq(self) -> None:
|
||||
self.freq_ = [0] * (max(self.v_) + 1)
|
||||
|
||||
for i in self.v_:
|
||||
self.freq_[i] += 1
|
||||
|
||||
def solve(self):
|
||||
self.process_freq()
|
||||
dp = [0] * (max(self.v_)+1)
|
||||
dp[1] = self.freq_[1]
|
||||
for i in range(2, len(dp)):
|
||||
dp[i] = max(dp[i-1], dp[i-2] + i * self.freq_[i])
|
||||
|
||||
print(dp[-1])
|
||||
|
||||
|
||||
def main():
|
||||
solver = Solver()
|
||||
solver.read_input()
|
||||
solver.solve()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user