码迷,mamicode.com
首页 > 其他好文 > 详细

P2089 烤鸡

时间:2019-07-18 19:26:29      阅读:93      评论:0      收藏:0      [点我收藏+]

标签:include   输入格式   输入输出   字典序   方案   cin   ace   cout   color   

题目背景

猪猪hanke得到了一只鸡

题目描述

猪猪Hanke特别喜欢吃烤鸡(本是同畜牲,相煎何太急!)Hanke吃鸡很特别,为什么特别呢?因为他有10种配料(芥末、孜然等),每种配料可以放1—3克,任意烤鸡的美味程度为所有配料质量之和

现在,Hanke想要知道,如果给你一个美味程度,请输出这10种配料的所有搭配方案

输入输出格式

输入格式:

 

一行,n<=5000

 

输出格式:

 

第一行,方案总数

第二行至结束,10个数,表示每种配料所放的质量

按字典序排列。

如果没有符合要求的方法,就只要在第一行输出一个“0”

#include<iostream>  
using namespace std;
int main()
{
    int a, b, c, d, e, f, g, h, i, j, in, x = 0;
    cin >> in;
    for (a = 1; a <= 3; a++)
    {
        for (b = 1; b <= 3; b++)
        {
            for (c = 1; c <= 3; c++)
            {
                for (d = 1; d <= 3; d++)
                {
                    for (e = 1; e <= 3; e++)
                    {
                        for (f = 1; f <= 3; f++)
                        {
                            for (g = 1; g <= 3; g++)
                            {
                                for (h = 1; h <= 3; h++)
                                {
                                    for (i = 1; i <= 3; i++)
                                    {
                                        for (j = 1; j <= 3; j++)
                                        {
                                            if (a + b + c + d + e + f + g + h + i + j == in)
                                            {
                                                x++;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    cout << x << endl;
    for (a = 1; a <= 3; a++)
    {
        for (b = 1; b <= 3; b++)
        {
            for (c = 1; c <= 3; c++)
            {
                for (d = 1; d <= 3; d++)
                {
                    for (e = 1; e <= 3; e++)
                    {
                        for (f = 1; f <= 3; f++)
                        {
                            for (g = 1; g <= 3; g++)
                            {
                                for (h = 1; h <= 3; h++)
                                {
                                    for (i = 1; i <= 3; i++)
                                    {
                                        for (j = 1; j <= 3; j++)
                                        {
                                            if (a + b + c + d + e + f + g + h + i + j == in)
                                            {
                                                cout << a << " ";
                                                cout << b << " ";
                                                cout << c << " ";
                                                cout << d << " ";
                                                cout << e << " ";
                                                cout << f << " ";
                                                cout << g << " ";
                                                cout << h << " ";
                                                cout << i << " ";
                                                cout << j << endl;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

 

P2089 烤鸡

标签:include   输入格式   输入输出   字典序   方案   cin   ace   cout   color   

原文地址:https://www.cnblogs.com/hsjj/p/P2089.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!