Luo Gu -P2089 chicken
Link to the original question: https://www.luogu.com.cn/problem/P2089
- Topic background
- Title Description
- Input Format
- Output Format
- Sample input and output
- Description / Tips
- C ++ code
Topic background
Pig Hanke got a chicken.
Title Description
Pig Hanke particularly like to eat roast chicken (this is the same beast, fratricidal!) Hanke chicken is very special. Why special? Because he has 10 ingredients (mustard, cumin, etc.), each ingredient can put 1-3 grams, the extent of any delicious roast chicken for all of the ingredients and quality.
Now, Hanke want to know, if you give a delicious degree n, the output of all your programs with these 10 ingredients.
Input Format
A positive integer n, the degree of delicacy.
Output Format
The first line, the total number of programs.
To the end of the second row, the number 10 represents the release of each ingredient quality, according to lexicographic order.
If there is no way to meet the requirements, so long as it is a 0 in the first line of output.
Sample input and output
Input # 1
11
Output # 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
Description / Tips
To 100% of the data, n≤5000.
C ++ code
#include <iostream>
using namespace std;
int n,len,d[10],ans[59049][10];
void dfs(int k, int m) {
if(k==10) {
if(m==n) {
for(int i=0;i<10;++i)
ans[len][i]=d[i];
++len;
}
return ;
}
for(int i=1;i<=3;++i)
{
if(m+i>n)
break;
d[k]=i;
dfs(k+1,m+i);
}
}
int main() {
cin>>n;
if(n<10||n>30) {
cout<<0<<endl;
return 0;
}
dfs(0,0);
cout<<len<<endl;
for(int i=0;i<len;++i)
{
for(int j=0;j<10;++j)
cout<<ans[i][j]<<' ';
cout<<endl;
}
return 0;
}