把数字拆分成递减序列

发布时间:2022-06-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了把数字拆分成递减序列脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
#include <iostream>
#include <vector>
using namespace std;
vector<int> t;
void traceback(int total, int n,int len) {    
    if (n == 0||total == 0) {
        for (int i = 0; i < t.size() - 1; i++) {
            if (t[i] < t[i + 1])return;
        }
        for (int i = 0; i < t.size();i++) {
            cout << t[i]+1 << ' ';
        }
        if (t.size() < len) {
            for (int i = 0; i < len - t.size();i++) {
                cout << 1 << ' ';
            }
        }
        cout << endl;
        return;
    }
    for (int i = total; i >=total/n&&i>0;i--) {
        t.push_back(i);
        traceback(total - i, n - 1, len);
        t.pop_back();
    }
}
int main() {
    int m, n;
    while (cin >> m >> n){
        int len = n;
        traceback(m - n, n,len);
    }
    return 0;
}

脚本宝典总结

以上是脚本宝典为你收集整理的把数字拆分成递减序列全部内容,希望文章能够帮你解决把数字拆分成递减序列所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: