30分求助
  • 板块P2089 烤鸡
  • 楼主SuperCheng
  • 当前回复1
  • 已保存回复1
  • 发布时间2023/3/28 22:18
  • 上次更新2023/10/23 20:10:23
查看原帖
30分求助
956190
SuperCheng楼主2023/3/28 22:18

跟之前提交的对比了半天,没剪枝有问题也只可能超时啊,为什么过都过不了了

#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;
}
2023/3/28 22:18
加载中...