烤鸡
题目背景
猪猪 Hanke 得到了一只鸡。
题目描述
猪猪 Hanke 特别喜欢吃烤鸡(本是同畜牲,相煎何太急!)Hanke 吃鸡很特别,为什么特别呢?因为他有 10 10 10 种配料(芥末、孜然等),每种配料可以放 1 1 1 到 3 3 3 克,任意烤鸡的美味程度为所有配料质量之和。
现在, Hanke 想要知道,如果给你一个美味程度 n n n ,请输出这 10 10 10 种配料的所有搭配方案。
输入格式
一个正整数 n n n,表示美味程度。
输出格式
第一行,方案总数。
第二行至结束, 10 10 10 个数,表示每种配料所放的质量,按字典序排列。
如果没有符合要求的方法,就只要在第一行输出一个 0 0 0。
样例 #1
样例输入 #1
11
样例输出 #1
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
提示
对于 100 % 100\% 100% 的数据, n ≤ 5000 n \leq 5000 n≤5000。
#include <bits/stdc++.h>
using namespace std;
int ans=0;
int demo[20000][10];
int temp[10];
void dfs(int now,int all)
{
if((now == 9))
{
if((all>0)&&(all<=3))
{
temp[now] = all;
for(int i=0;i<10;i++)
{
demo[ans][i] = temp[i];
}
ans++;
return ;
}
else return ;
}
if(all<= 0) return ;
for(int i=1;i<=3;i++)
{
temp[now] = i;
dfs(now+1,all-i);
}
}
int main()
{
int all=0;
cin>>all;
dfs(0,all);
cout<<ans<<endl;
for(int j=0;j<ans;j++)
{
for(int i=0;i<10;i++)
{
cout<<demo[j][i]<<' ';
}cout<<endl;
}
}