不知道哪里错了 救救孩子
  • 板块P2089 烤鸡
  • 楼主Haii
  • 当前回复0
  • 已保存回复0
  • 发布时间2022/8/5 20:57
  • 上次更新2023/10/27 16:50:02
查看原帖
不知道哪里错了 救救孩子
601916
Haii楼主2022/8/5 20:57
#include <iostream>
#include <cstring>
#include <queue>
#include <algorithm>
#include <vector>
#include <functional>
#include <set>
#include <map>
#include <string>

using namespace std;

int ans;	
int n;
int q[20];
int res[100001][20];

void dfs(int u,int tot)
{
	if (u > 10)
	{
		if (tot == n)
		{
			for (int i = 1; i <= 10; i++) res[ans][i] = q[i];
			ans++;
		}
		return;
	}
	for (int i = 1; i <= 3; i++)
	{
		if (tot + i > n) break;
		q[u] = i;
		dfs(u + 1, tot + i);
	}
}

int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	if (n < 10 || n > 30)
	{
		cout << 0;
		return 0;
	}

	dfs(1, 0);
	cout << ans << endl;
	for (int i = 0; i < ans; i++)
	{
		for (int j = 1; j <= 10; j++)
		{
			cout << res[i][j] << ' ';
		}
		puts("");
	}
	return 0;
}
2022/8/5 20:57
加载中...