20WA,求助qwq
查看原帖
20WA,求助qwq
1438293
LiuStar2233楼主2025/1/20 14:12

#2 #4 #5 #6 #7都WA了,有米有dalao帮帮我qwq

// P2036 [COCI2008-2009 #2] PERKET
#include <bits/stdc++.h>
using namespace std;

int n, s[12], b[12], min_diff = INT_MAX;
void dfs(int index, int current_s, int current_b) {
    if (index == n + 1) {
        min_diff = min(min_diff, abs(current_s - current_b));
        return;
    }

    dfs(index + 1, current_s, current_b);
    current_s *= s[index];
    current_b += b[index];
    dfs(index + 1, current_s, current_b);
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
        scanf("%d%d", &s[i], &b[i]);
    dfs(1, 1, 0);
    printf("%d", min_diff);

    return 0;
}
2025/1/20 14:12
加载中...