其他分享
首页 > 其他分享> > P2089 烤鸡

P2089 烤鸡

作者:互联网

// Problem: P2089 烤鸡
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P2089
// Memory Limit: 125 MB
// Time Limit: 1000 ms
// User: Pannnn

#include <bits/stdc++.h>

using namespace std;

void dfs(vector<vector<int>> &res, vector<int> &tmp, int sum, int n, int pos) {
    if (pos >= 10) {
        if (sum == n) {
            res.push_back(tmp);
        }
        return;
    }
    
    for (int i = 1; i <= 3; ++i) {
        tmp[pos] = i;
        dfs(res, tmp, sum + i, n, pos + 1);
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    vector<vector<int>> res;
    int n;
    cin >> n;
    
    vector<int> tmp(10);
    dfs(res, tmp, 0, n, 0);
    cout << res.size() << endl;
    for (int i = 0; i < res.size(); ++i) {
        for (int j = 0; j < res[i].size(); ++j) {
            cout << res[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}

标签:tmp,int,res,pos,烤鸡,P2089,vector
来源: https://www.cnblogs.com/pannnn/p/15867356.html