1 条题解

  • 0
    @ 2024-12-6 20:35:43

    #include<bits/stdc++.h> using namespace std; int n, k;

    int read(){ int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9'){ if (ch == '-')f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9'){ x = x * 10 + ch - '0'; ch = getchar(); } return x * f; }

    int a[12001];

    bool pd(int k){ for (int i = 2;i * i <= k;i ++) if (k % i == 0) return 0; return 1; }

    int s;

    void dfs(int x, int y, int z){ if (x == k && pd(y)){ ++ s; return ; } for (int i = z;i < n;i ++) dfs(x + 1, y + a[i], i + 1); return ; }

    int main() { n = read(), k = read(); for (int i = 0;i < n;i ++)a[i] = read(); dfs (0, 0, 0); printf("%d\n", s); return 0; }

    • 1

    信息

    ID
    5094
    时间
    1000ms
    内存
    125MiB
    难度
    2
    标签
    递交数
    199
    已通过
    101
    上传者