hdu 6772 Lead of Wisdom暴力搜索

文章目录

  • 题目
  • 思路
  • 代码

题目链接

题目

hdu 6772 Lead of Wisdom暴力搜索_第1张图片
hdu 6772 Lead of Wisdom暴力搜索_第2张图片

思路

枚举所有的情况然后暴力搜索
在这里插入图片描述
我是没想到,和队友讨论了半天,最后某人分析了一下复杂度说可以暴力,我随手写个暴力搜索居然过了

代码

#include

using namespace std;

struct node {
    long long t, a, b, c, d;

    node() {}

    node(int a, int b, int c, int d) :
            a(a), b(b), c(c), d(d) {}

    bool operator<(const node &r) {
        return t < r.t;
    }
};

int shai_xuan_jie_guo[55], iter_len;
node items[55];
int begin_of_each_kind_of_item[55];
int cnt, n, k;

inline long long dmg(int kind) {
    long long a = 0, b = 0, c = 0, d = 0;
    for (int i = 0; i < kind; ++i) {
        node &x = items[shai_xuan_jie_guo[i]];
        a += x.a, b += x.b, c += x.c, d += x.d;
    }
    return (100 + a) * (100 + b) * (100 + c) * (100 + d);
}

long long ans;

void dfs(int kind) {
    if (kind == cnt) {
        ans = max(ans, dmg(kind));
        return;
    }
    for (int i = begin_of_each_kind_of_item[kind]; i < begin_of_each_kind_of_item[kind + 1]; ++i) {
        shai_xuan_jie_guo[kind] = i;
        dfs(kind + 1);
    }
}

int main() {
    //ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while (t--) {
        scanf("%d%d", &n, &k);
        for (int i = 0; i < n; ++i) {
            node &x = items[i];
            scanf("%lld%lld%lld%lld%lld", &x.t, &x.a, &x.b, &x.c, &x.d);
        }
        sort(items, items + n);
        begin_of_each_kind_of_item[0] = 0;
        cnt = 1;
        ans = 0;
        for (int i = 1; i < n; ++i) {
            if (items[i].t != items[begin_of_each_kind_of_item[cnt - 1]].t) {
                begin_of_each_kind_of_item[cnt++] = i;
            }
            begin_of_each_kind_of_item[cnt] = n;
        }
        dfs(0);
        printf("%lld\n", ans);
    }
    return 0;
}

你可能感兴趣的:(暴力,搜索)