The Strongest Build 暴搜

#include <bits/stdc++.h>
#define sc(x) scanf("%lld", &(x))
#define pr(x) printf("%lld\n", (x))
#define rep(i, l, r) for (int i = l; i <= r; ++i)
using namespace std;
typedef long long ll;

const int N = 11;

set<vector<int>> ban;
vector<int> a[N];
ll sum = 0, ans = 0;
vector<int> now, best;
int n;
bool dfs(int i) {
    if (i == n) {
        if (ban.count(now)) return 1;
        if (ans < sum) best = now, ans = sum;
        return 0;
    }

    bool was = 0;
    for (int j = a[i].size() - 1; j >= 0; --j) {
        sum += a[i][j];
        now.emplace_back(j + 1);
        bool ret = dfs(i + 1);
        now.pop_back();
        sum -= a[i][j];
        if (ret)
            was = 1;
        else
            break;
    }
    return was;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 0, k; i < n; ++i) {
        cin >> k;
        a[i].resize(k);
        for (int& x : a[i]) cin >> x;
    }

    int m;
    cin >> m;
    for (int i = 0; i < m; ++i) {
        vector<int> t(n);
        for (int& x : t) cin >> x;
        ban.insert(t);
    }

    dfs(0);
    for (const int& x : best) cout << x << ' ';
    cout << '\n';
    return 0;
}
算法竞赛之路 文章被收录于专栏

整理、记录算法竞赛的好题

全部评论

相关推荐

本神尊:看来是没招到小红薯上的人
点赞 评论 收藏
分享
06-17 00:26
门头沟学院 Java
程序员小白条:建议换下项目,智能 AI 旅游推荐平台:https://github.com/luoye6/vue3_tourism_frontend 智能 AI 校园二手交易平台:https://github.com/luoye6/vue3_trade_frontend GPT 智能图书馆:https://github.com/luoye6/Vue_BookManageSystem 选项目要选自己能掌握的,然后最好能自己拓展的,分布式这种尽量别去写,不然你只能背八股文了,另外实习的话要多投,尤其是学历不利的情况下,多找几段实习,最好公司title大一点的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务