【悬关】16分#2 AC 其他WA 求助
查看原帖
【悬关】16分#2 AC 其他WA 求助
1080505
Asaha_Akina楼主2024/3/30 20:02

求助! 代码如下:

//C++
#include <bits/stdc++.h>
using namespace std;
static int total, chosen, numbers[22], chosenArray[22];
int counter = 0;
void search(int depth) {
    //int judge = 0;
    if (depth == chosen) {
        int sum = 0;
        for (int i = 0; i < chosen; ++i) {
            sum += chosenArray[i];
        }
        if (sum == 2) {
            counter++;
            return;
        } else if (sum > 2) {
            for (int i = 2; i * i <= sum; ++i) {
                if (sum % i == 0) {
                    return;
                }
            }
            counter++;
        }
        return;
    }
    for (int i = 0; i < total; ++i) {
        chosenArray[depth] = numbers[i];
        search(depth + 1);
        /*
        if (depth > 1) {
            for (int j = 0; j < i; ++j) {
                if (chosenArray[j] == chosenArray[depth]) {
                    judge = 1;
                }
            }
        }
        if (judge == 0) {
            search(depth + 1);
        }
        judge = 0;
         */
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin >> total;
    for (int i = 0; i < total; ++i) {
        cin >> numbers[i];
    }
    search(0);
    cout << counter;
}
2024/3/30 20:02
加载中...