比赛 20241125 评测结果 AAAAAAAAA
题目名称 夏娜的菠萝包 最终得分 100
用户昵称 darkMoon 运行时间 1.167 s
代码语言 C++ 内存使用 4.73 MiB
提交时间 2024-11-25 08:34:34
显示代码纯文本
#include<bits/stdc++.h>
#define int long long
using namespace std;
auto IN = freopen("shana.in", "r", stdin);
auto OUT = freopen("shana.out", "w", stdout);
auto mread = [](){int x;scanf("%lld", &x);return x;};
int n;
signed main(){
    while(cin >> n){
        if(n == 0){
            return 0;
        }
        int a[n + 5], b[n + 5];
        for(int i = 1; i <= n; i ++){
            cin >> a[i] >> b[i];
        }
        int m = mread();
        int k[m + 5], e[m + 5], bit[m + 5] = {0}, sum[m + 5] = {0}, de[m + 5] = {0}, life[m + 5];
        vector<int> v[m + 5];
        for(int i = 1; i <= m; i ++){
            cin >> k[i] >> e[i];
            life[i] = n;
            v[i] = vector<int>(k[i] + 5, 0);
            for(int j = 1; j <= k[i]; j ++){
                cin >> v[i][j];
                if(1 & (bit[i] >> v[i][j])){
                    life[i] = -1;
                }
                sum[i] += a[v[i][j]];
                de[i] += b[v[i][j]];
                life[i] = min(life[i], a[v[i][j]] / b[v[i][j]]);
                bit[i] += 1 << v[i][j];
            }
            // cout << i << " " << (bitset<5>)bit[i] << " " << sum[i] << " " << de[i] << " " << life[i] << "\n";
        }
        int ma = 1 << n + 1;
        vector<vector<int> > f(n + 5, vector<int>(ma + 5, -0x3f3f3f3f));
        f[0][0] = 0;
        for(int i = 0; i < n; i ++){
            for(int now = 0; now < ma; now ++){
                for(int j = 1; j <= m; j ++){
                    if((now & bit[j]) == 0 && life[j] >= i){
                        f[i + 1][now ^ bit[j]] = max(f[i + 1][now ^ bit[j]], f[i][now] + e[j] + sum[j] - i * de[j]);
                    }
                }
            }
        }
        int ans = 0;
        for(int i = 0; i <= n; i ++){
            for(int now = 0; now < ma; now ++){
                ans = max(ans, f[i][now]);
            }
        }
        printf("%lld\n", ans);
    }
    return 0;
}