链接:https://codeforces.ml/problemset/problem/1097/B
题意:判断能否用所给的数据凑出360的倍数或者0;
题解:
n才15,暴力dfs走起;
代码:
#include<bits/stdc++.h> using namespace std; typedef long long ll; int num[100005] = { 0 }; int ans = 0; void dfs(int step, int n, int sum) { /*cout << sum <<" " << " ";*/ if (step == n+1) { cout << endl; if (sum == 0) { /* cout << "1";*/ ans = 1; } else if (sum % 360 == 0) { /*cout << '2';*/ ans = 1; } return; } dfs(step + 1, n, sum + num[step]); dfs(step + 1, n, sum - num[step]); } int main() { int t; cin >> t; for (int i = 1; i <= t; i++) { cin >> num[i]; } dfs(1, t, 0); //cout << ans; if (ans==1) cout << "YES"; else cout << "NO"; }