codeforces - 1097B Petr and a Combination Lock

 

题目链接:https://vjudge.net/problem/CodeForces-1097B

对于给出的每一个度数,我们只有两种情况,要么加上它要么减去它,因为题目给出的n最大只有15,所以当然是选择暴☆搜啦。

#include<set>
#include<map>
#include<stack>
#include<queue>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<string>
#include<vector>
#include<climits>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
#define mst(a) memset(a, 0, sizeof(a))
#define _test printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n")
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const double eps = 1e-7;
const int INF = 0x3f3f3f3f;
const ll ll_INF = 233333333333333;
const int maxn = 4e6 + 10;
int arr[maxn];
bool dfs(int i, int n, int sum) {
    if (i == n) 
        return !(sum % 360);
    return dfs(i+1, n, sum + arr[i]) || dfs(i+1, n, sum - arr[i]);
}
int main(void) {
    int n;
    cin >> n;
    for (int i = 0; i<n; i++)
        cin >> arr[i];
    printf(dfs(0,n,0) ? "YES\n" : "NO\n");
    return 0;
}

posted @ 2019-12-10 08:00  shuitiangong  阅读(138)  评论(0编辑  收藏  举报