-
-
Save neizod/3418331 to your computer and use it in GitHub Desktop.
ACM-ICPC Thailand Central 2012
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fractions import Fraction | |
from math import factorial | |
from operator import mul | |
from functools import reduce | |
def product(member): | |
return reduce(mul, member) | |
def repile(minimum, remain_piles, remain_dishes, case, stack=[]): | |
if remain_piles == 1: | |
if remain_dishes >= stack[-1]: | |
case.append(stack+[remain_dishes]) | |
for each in range(minimum, remain_dishes): | |
repile(each, remain_piles-1, remain_dishes-each, case, stack+[each]) | |
for test in range(int(input())): | |
dishes, least = [int(num) for num in input().split()] | |
piles = dishes // least | |
every_case = [] | |
every_case.append([dishes]) | |
for remain_pile in range(2, piles+1): | |
minimum = least | |
repile(minimum, remain_pile, dishes, every_case) | |
possible = 0 | |
for line in every_case: | |
unique = set(line) | |
repeat = [line.count(each) for each in unique] # optimiz: if count > 1 | |
div = product([factorial(each) for each in repeat+line]) | |
possible += Fraction(factorial(dishes), div) | |
# print(repeat, line, div, possible) | |
print(possible % 9871) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for test in range(int(input())): | |
rows, cols = [int(num) for num in input().split()] | |
earth = [] | |
for row in range(rows): | |
if row == 0: | |
earth = [int(num) for num in input().split()] | |
else: | |
prev = earth[:] | |
curr = [int(num) for num in input().split()] | |
earth = [] | |
for col in range(cols): | |
if col == 0: | |
plus = min([prev[col], prev[col+1]]) | |
elif col == cols-1: | |
plus = min([prev[col-1], prev[col]]) | |
else: | |
plus = min([prev[col-1], prev[col], prev[col+1]]) | |
earth.append(curr[col]+plus) | |
print(min(earth)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
foods = [4, 4, 4, 100] | |
day = 0 | |
while all(foods): | |
foods.sort(reverse=True) | |
frig = foods.pop() | |
foods = [food-1 for food in foods] | |
foods.append(frig) | |
day += 1 | |
print('longest days =', day) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment