跟之前提交的对比了半天,没剪枝有问题也只可能超时啊,为什么过都过不了了
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 59100;
const int M = 15;
int ideas[N][M];
int arr[M];
int n, res = 0;
void dfs(int x, int s){
if (x > 10){
if (s == n){
res++;
for (int i = 1; i <= 10; i++){
ideas[res][i] = arr[i];
}
}
return;
}
for (int i = 1; i <= 3; i++){
arr[x] = i;
dfs(x + 1, s + i);
}
}
int main(){
scanf("%d", &n);
dfs(1, 0);
printf("%d", res);
for (int i = 1; i <= res; i++){
for (int j = 1; j <= 10; j++){
printf("%d ", ideas[i][j]);
}
}
return 0;
}