本題地址:http://www.luogu.org/problem/show?pid=2089
題目背景
豬豬hanke得到了一隻雞
題目描述
豬豬Hanke特別喜歡喫烤雞(本是同畜牲,相煎何太急!)Hanke喫雞很特別,爲什麼特別呢?因爲他有10種配料(芥末、孜然等),每種配料可以放1—3克,任意烤雞的美味程度爲所有配料質量之和
現在,Hanke想要知道,如果給你一個美味程度,請輸出這10種配料的所有搭配方案
輸入輸出格式
輸入格式:
一行,n<=20
輸出格式:
第一行,方案總數
第二行至結束,10個數,表示每種配料所放的質量
按字典序排列。
輸入輸出樣例
輸入樣例#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
說明
枚舉
寫了個dfs,居然沒過,怒之,寫了個10重枚舉,居然過了
#include
#include
#include
using namespace std;
int n,ans=0;
int main()
{
cin>>n;
for(int a=1;a<=3;a++)
for(int b=1;b<=3;b++)
for(int c=1;c<=3;c++)
for(int d=1;d<=3;d++)
for(int e=1;e<=3;e++)
for(int f=1;f<=3;f++)
for(int g=1;g<=3;g++)
for(int h=1;h<=3;h++)
for(int i=1;i<=3;i++)
for(int j=1;j<=3;j++)
{if(a+b+c+d+e+f+g+h+i+j==n)
ans++;
}
cout<<ans<<endl;
for(int a=1;a<=3;a++)
for(int b=1;b<=3;b++)
for(int c=1;c<=3;c++)
for(int d=1;d<=3;d++)
for(int e=1;e<=3;e++)
for(int f=1;f<=3;f++)
for(int g=1;g<=3;g++)
for(int h=1;h<=3;h++)
for(int i=1;i<=3;i++)
for(int j=1;j<=3;j++)
{if(a+b+c+d+e+f+g+h+i+j==n)
{cout<<a<<' ';
cout<<b<<' ';
cout<<c<<' ';
cout<<d<<' ';
cout<<e<<' ';
cout<<f<<' ';
cout<<g<<' ';
cout<<h<<' ';
cout<<i<<' ';
cout<<j<<' '<<endl;
}
}
return 0;
}