Skip to content

Instantly share code, notes, and snippets.

@yodalee
Created February 4, 2022 15:29
Show Gist options
  • Save yodalee/1a1f42aced3d8cbaf1f1208e1b94b679 to your computer and use it in GitHub Desktop.
Save yodalee/1a1f42aced3d8cbaf1f1208e1b94b679 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
PAGES = 180
DAYS = 14
memo = {}
def search(page: int, days: int) -> int:
if (page, days) in memo:
return memo[(page, days)]
if days == 1:
return 1
cnt = 0
oneday = ((page - days * (days - 1) // 2) // days);
for i in range(1, oneday+1):
cnt += search(page - i * days, days - 1);
memo[(page, days)] = cnt
return cnt
def main():
PAGES = 180
DAYS = 14
memo = []
cnt = 0
for i in range(1, DAYS+1):
cnt += search(PAGES, i);
print(cnt)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment