牛客算法周周练2 B. Music Problem(状压dp)

题目链接:https://ac.nowcoder.com/acm/contest/5203/B

题意

给出 $n$ 个数,能否从中选取某些数加起来为 $3600$ 的倍数。

代码

#include <bits/stdc++.h>
using namespace std;
const int N = 7210;

bitset<N> dp;

void solve() {
    int n; cin >> n;
    dp.reset();
    dp[0] = 1;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        x %= 3600;
        dp |= dp << x;
        dp |= dp >> 3600;
    }
    cout << (dp[3600] ? "YES" : "NO") << "\n";
}

int main() {
    int t; cin >> t;
    while (t--) solve();
}

 

posted @ 2020-05-31 22:22  Kanoon  阅读(170)  评论(0)    收藏  举报