code4sk/c/sourcecode/AlgorithmO/20230911/穿错衣服问题.py
2023-10-18 16:17:32 +08:00

28 lines
1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#
'''
E. 穿错衣服问题
Description
SmallBeer曾经当过兵他常常回忆起刚入伍时的情景。记得那时周末只有一天休息而且部队规定休息天外出营区只能有三分之一人数所以大家都很珍惜周末外出的机会一旦外出肯定要尽情享受一天的乐趣但部队规定下午五点必须归队因此大家外出后回来都很匆忙。其中最有意思的是早上外出前大家都把军装洗完晾好下午归队时赶紧穿上但由于时间紧常常发生穿错衣服的事件现在请你这个编程高手想办法算算所有人都穿错的情况有多少种
Input
有多组测试数据对于每一组测试数据输入只有一行即总人数n(1<=n<=1000)。
Output
对于每一组的输入,输出只有一行,即所有人都穿错的情况数。
Sample Input
1
2
Sample Output
0
1
'''
a=[0,0,1]
for i in range(3,1010):
a.append((i-1)*(a[i-2]+a[i-1]))
while True:
try:
n=int(input())
print(a[n])
except:
break