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
0721 - CD
(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="python" line> #0721 - CD def read_input(file_name): try: with open(file_name, 'r') as file: n, S = map(int, file.readline().split()) data = [tuple(map(int, line.split())) for line in file.readlines()] if not (2 <= n <= 300 and S % n == 0 and all(0 <= y <= 1000 and 1 <= c <= n for y, c in data)): raise ValueError("Numerele nu respecta restricțiile.") return n, S, data except Exception as e: print(f"Nu au fost respectate cerintele impuse: {str(e)}") return None def write_output(file_name, result): with open(file_name, 'w') as file: if result is not None: file.write(f"{result}\n") def count_ways(n, S, data): mod = 9901 dp = [0] * (S + 1) dp[0] = 1 for y, c in data: for i in range(S, y - 1, -1): dp[i] = (dp[i] + dp[i - y] - dp[i - y - 1] + mod) % mod return dp[S] def main(input_file, output_file): result = read_input(input_file) if result is not None: n, S, data = result result = count_ways(n, S, data) write_output(output_file, result) if __name__ == "__main__": main("cdin.txt", "cdout.txt") </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