Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Bitnami MediaWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
0730 - Minus K
(section)
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Rezolvare== <syntaxhighlight lang="python3" line="1"> MOD = 2011 def numar_siruri(N, K): # Inițializăm matricea dp cu 0-uri dp = [[0] * 2 for _ in range(N + 1)] # Prima coloană este 1, pentru că există un singur șir de lungime 0, și anume șirul vid dp[0][0] = 1 # Calculăm numărul de șiruri for i in range(1, N + 1): # Dacă adăugăm + în șirul anterior, nu adăugăm un semn - pe poziția i dp[i][0] = (dp[i - 1][0] + dp[i - 1][1]) % MOD # Dacă adăugăm - în șirul anterior, verificăm dacă am adăugat deja K semne - consecutive if i >= K: dp[i][1] = (dp[i - 1][0] - dp[i - K][1] + MOD) % MOD else: dp[i][1] = dp[i - 1][0] return (dp[N][0] + dp[N][1]) % MOD if __name__ == "__main__": with open("minusk.in", "r") as f: N, K = map(int, f.readline().split()) rezultat = numar_siruri(N, K) with open("minusk.out", "w") as g: g.write(str(rezultat) + "\n") </syntaxhighlight>
Summary:
Please note that all contributions to Bitnami MediaWiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Bitnami MediaWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width