[TIOJ]1993. 冰塊塔

題目連結:http://tioj.infor.org/contests/55/problems/1993

背包問題,但是需要用bitset壓常數。
#include <iostream>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <queue>
#include <vector>
#define lld long long
#define PB push_back
#define F first
#define S second
#define jizz cin.tie(0);ios_base::sync_with_stdio(0);
#define endl '\n'
using namespace std;
typedef pair<int,int> Pair;
bitset<100005> ok;
int main(){jizz
    int t;cin >> t;
    while(t--){
        ok.reset();
        int n,h;cin >> n >> h;
        ok[0] = 1;
        for(int i = 0 ; i < n ; i++){
            int a,b,c;cin >> a >> b >> c;
            ok = (ok << a)|(ok << b)|(ok << c);
        }
        int ans = 0;
        for(int i = 0 ; i <= h ; i++)if(ok[i])ans = i;
        if(!ans)cout <<"no solution" << endl;
        else cout << ans << endl;
    }
    return 0;
}


留言

這個網誌中的熱門文章

[TIOJ]1617. [Interactive] 中位數

[TIOJ]1337. 隕石

[TIOJ]1994. 冰塊線