zoukankan      html  css  js  c++  java
  • 2089烤鸡(类似于选数问题)

    #include <iostream>
    #include <cstdio>
    using namespace std;
    int b[100];
    int c[100];
    int a[3] = { 1,2,3 };
    int ans;
    int n;
    void fun(int depth, int sum)
    {
        if (depth == 10 && sum == n)//结束条件
        {
            for (int i = 0; i < 10; i++)
                cout << b[i] << " ";
            cout << endl;
            return;
        }
        if (sum > n || depth > 10)//剪枝
            return;
        for (int i = 0; i < 3; i++)//3种质量
        {
            b[depth] = a[i];
            fun(depth + 1, sum + a[i]);
        }
    }
    void rec(int depth, int sum)//完全模仿上一个函数,不过是为了搞出ans,并且满足输出格式(即先输出ans))
    {
        if (depth == 10 && sum == n)//结束条件
        {
            ans++;
            return;
        }
        if (sum > n || depth > 10)//剪枝
            return;
        for (int i = 0; i < 3; i++)//3种质量
        {
            c[depth] = a[i];
            rec(depth + 1, sum + a[i]);
        }
    }
    int main()
    {
       
        cin >> n;
        rec(0,0);
        cout<<ans<<endl;
        fun(0,0);
        return 0;
    }
    这篇文章,是又一个故事的结束...
    lazy's story is continuing.
  • 相关阅读:
    离散数学--第十章 群,环,域
    离散数学--十一章 格与布尔代数
    matplotlib 基础|笔记
    CF Round #632 div2
    Codeforces Round#630 div2
    PVZ 2--攻略合集?
    【POJ
    【POJ
    【Aizu
    【Aizu
  • 原文地址:https://www.cnblogs.com/Hello-world-hello-lazy/p/14379749.html
Copyright © 2011-2022 走看看