P2089 烤鸡

原题链接 https://www.luogu.com.cn/problem/P2089

题目描述

十种配料各取 1 到 3 克,列出总重量恰好等于 n 的所有搭配。

输入 一个正整数 n。

输出 第一行是方案总数,随后按字典序输出每种搭配的十个用量。无解时只输出 0。

输入输出样例

输入

11

输出

10
1 1 1 1 1 1 1 1 1 2 
1 1 1 1 1 1 1 1 2 1 
1 1 1 1 1 1 1 2 1 1 
1 1 1 1 1 1 2 1 1 1 
1 1 1 1 1 2 1 1 1 1 
1 1 1 1 2 1 1 1 1 1 
1 1 1 2 1 1 1 1 1 1 
1 1 2 1 1 1 1 1 1 1 
1 2 1 1 1 1 1 1 1 1 
2 1 1 1 1 1 1 1 1 1 

题解

from itertools import product
n=int(input())
if 10<=n<=30:
    a=[t for t in product(range(1,4),repeat=10) if sum(t)==n]
    print(len(a))
    for i,x in enumerate(a):
        print(*x)
else:
    print(0)