P2089 烤鸡【暴力枚举】
likztime
2018-01-30 09:37:14
# 枚举做法
题目背景
猪猪hanke得到了一只鸡
题目描述
猪猪Hanke特别喜欢吃烤鸡(本是同畜牲,相煎何太急!)Hanke吃鸡很特别,为什么特别呢?因为他有10种配料(芥末、孜然等),每种配料可以放1—3克,任意烤鸡的美味程度为所有配料质量之和
现在,Hanke想要知道,如果给你一个美味程度,请输出这10种配料的所有搭配方案
输入输出格式
输入格式:
一行,n<=5000
输出格式:
第一行,方案总数
第二行至结束,10个数,表示每种配料所放的质量
按字典序排列。
如果没有符合要求的方法,就只要在第一行输出一个“0”
输入输出样例
输入样例#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
## 题目分析:没什么难的,看数据是在1-3之间,可以暴力枚举,有时间做一个回溯烤鸡
```cpp
#include<cmath>
#include<cctype>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<set>
#include<stack>
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
int n,x=0;
bool fuck=0;
scanf("%d",&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) {
x++;
fuck=1;
}
}
if(fuck)printf("%d\n",x);
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) {
printf("%d %d %d %d %d %d %d %d %d %d\n",a,b,c,d,e,f,g,h,i,j);
}
}
if(!fuck)printf("0\n");
return 0;
}
```