Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination lock! The lock has a scale of 360360 degrees and a pointer which initially points at zero:

Petr called his car dealer, who instructed him to rotate the lock's wheel exactly nn times. The ii-th rotation should be aiai degrees, either clockwise or counterclockwise, and after all nn rotations the pointer should again point at zero.

This confused Petr a little bit as he isn't sure which rotations should be done clockwise and which should be done counterclockwise. As there are many possible ways of rotating the lock, help him and find out whether there exists at least one, such that after all nn rotations the pointer will point at zero again.

Input

The first line contains one integer nn (1≤n≤151≤n≤15) — the number of rotations.

Each of the following nn lines contains one integer aiai (1≤ai≤1801≤ai≤180) — the angle of the ii-th rotation in degrees.

Output

If it is possible to do all the rotations so that the pointer will point at zero after all of them are performed, print a single word "YES". Otherwise, print "NO". Petr will probably buy a new car in this case.

You can print each letter in any case (upper or lower).

Examples
input

Copy
3
10
20
30
output

Copy
YES
input

Copy
3
10
10
10
output

Copy
NO
input

Copy
3
120
120
120
output

Copy
YES
Note

In the first example, we can achieve our goal by applying the first and the second rotation clockwise, and performing the third rotation counterclockwise.

In the second example, it's impossible to perform the rotations in order to make the pointer point at zero in the end.

In the third example, Petr can do all three rotations clockwise. In this case, the whole wheel will be rotated by 360360 degrees clockwise and the pointer will point at zero again.


前 i 次旋转下,是否可以旋转到 j 度的位置,那么转移方程有:dp[i][j] = dp[ i - 1 ][ j - a[i] ] | dp[ i - 1 ][ j + a[i] ]

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <numeric>
#include <cmath>
#include<unordered_set>
#define ll long long
using namespace std;
int dir[][] = { {,},{-,},{,},{,-} }; int main()
{
int n;
cin >> n;
vector<int> a(n+1);
for (int i = 1; i <= n; i++)
cin >> a[i];
vector<vector<bool>> dp(16, vector<bool>(360));
dp[0][0] = true;
for (int i = 1; i <= n; i++)
{
for (int j = 0; j < 360; j++)
{
if (dp[i - 1][(j - a[i] + 360) % 360])
dp[i][j] = true;
if (dp[i - 1][(j + a[i] + 360) % 360])
dp[i][j] = true;
}
}
cout << (dp[n][0] ? "YES" : "NO") << endl;
//system("pause");
return 0;
}

Petr and a Combination Lock的更多相关文章

  1. B.Petr and a Combination Lock

    https://codeforces.com/contest/1097/problem/A Petr and a Combination Lock time limit per test 1 seco ...

  2. CF1097B Petr and a Combination Lock 题解

    Content 有一个锁,它只有指针再次指到 \(0\) 刻度处才可以开锁(起始状态如图所示,一圈 \(360\) 度). 以下给出 \(n\) 个操作及每次转动度数,如果可以通过逆时针或顺时针再次转 ...

  3. Combination Lock

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview room. You know that a Micr ...

  4. hihocoder #1058 Combination Lock

    传送门 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview room. You know that a ...

  5. 贪心 Codeforces Round #301 (Div. 2) A. Combination Lock

    题目传送门 /* 贪心水题:累加到目标数字的距离,两头找取最小值 */ #include <cstdio> #include <iostream> #include <a ...

  6. Codeforces Round #301 (Div. 2) A. Combination Lock 暴力

    A. Combination Lock Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/540/p ...

  7. Hiho----微软笔试题《Combination Lock》

    Combination Lock 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview room. You ...

  8. CF #301 A :Combination Lock(简单循环)

    A :Combination Lock 题意就是有一个密码箱,密码是n位数,现在有一个当前箱子上显示密码A和正确密码B,求有A到B一共至少需要滚动几次: 简单循环:

  9. hihocoder-第六十一周 Combination Lock

    题目1 : Combination Lock 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview roo ...

随机推荐

  1. 【分享】一款特别轻量的gif生成工具

    github链接:https://github.com/NickeManarin/ScreenToGif/releases/tag/2.19.3 超级好用!支持多种方式(摄像头也可√)录制gif

  2. K3/Cloud 执行计划任务错误排查

    计划任务的不执行原因可能有: 1.K3CloudJobProcess服务处于停止状态. 2.数据中心未勾选“允许执行计划任务”. 这种情况此数据中心下的所有计划任务都不会执行到. 3.第一次加进计划任 ...

  3. 网页出现横向滚动条的原因可能是使用bootstrap不当引起

    Bootstrap的栅格布局超级方便我们写网页.但是在不是全体配合使用的情况下,会出现横向滚动条的现象. 什么叫不是配合使用的情况呢? >>一种情况是:你使用了row作为你的第一层父元素: ...

  4. [Note]prufer

    [Note]Prufer编码 实现 不断删除度数为\(1\)的最小序号的点,并输出与其相连的节点的序号,直至树中只有两个节点. 性质 任何一棵\(n\)节点的树都可以唯一的用长度为\(n-2\)的pr ...

  5. redis 有序集合(set),无需集合(zset)

    1.set(无序集合)无序集合每个元素都是string元素的唯一性,不能重复没有修改操作 1.增加 sadd key value1 value2 value3... 2.获取 smembers key ...

  6. JavaScript DOM–节点操作

    节点 节点至少拥有nodeType(节点类型).nodeName(节点名称)和nodeValue(节点值)这三个基本属性. 元素节点 nodeType  为1 属性节点 nodeType  为2 文本 ...

  7. sort函数的用法(C++排序库函数的调用)

    对数组进行排序,在c++中有库函数帮我们实现,这们就不需要我们自己来编程进行排序了. (一)为什么要用c++标准库里的排序函数 Sort()函数是c++一种排序方法之一,学会了这种方法也打消我学习c+ ...

  8. 04 部署uwsgi web服务器

    1 建立uwsgi软链接 进入虚拟环境,并在虚拟环境中安装uwsgi,建立软链接. $ cd /venv/thvenv/bin $ activate $ pip install uwsgi 2 创建u ...

  9. mysql-sql分析策略及优化

    tranlation事务:从失败中回复到正常状态的方法多个应用并发访问数据库时,提供隔离方法 acid原子性:要么成功.要么失败一致性:数据保持“合理性”隔离型:多个事务同时并发执行,每个事务就像各自 ...

  10. 构造和改变一个string的其他方法

    构造一个string的其他方法: 1string s1(cp, n),cp为c风格数组名或一个指向C风格数组的指针,则执行的操作为拷贝从cp开始包括cp在内的接下来n个字符给s1,n的默认值为size ...