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. Application Characteristics Of LED Keychain

    LED keychains are essential camping and travel accessories. Very useful as a light source. There are ...

  2. [CF1216C] White Sheet - 离散化,模拟

    虽然分类讨论应该是比较推崇的解法,但是我就是喜欢暴力 #include <bits/stdc++.h> using namespace std; #define int long long ...

  3. django实现简易登录注册

    经过一些文档的理解,以及一些时间的琢磨.我觉得可以用django做一些小项目了 先说说登录功能吧. 先创建一个app,用admin命令 在cmd打开到manage.py同级目录下,django-adm ...

  4. 关于XXE

    NJUPT CTF2019: 做题的时候,抓包看了一下,响应XML格式消息,并没有严格过滤,这道题读文件, <!DOCTYPE foo [ <!ENTITY xxe SYSTEM &quo ...

  5. SpringBoot学习- 9、Slf4j日志

    SpringBoot学习足迹 在上一篇学习中 通过画红线的注解,可以直接在下面log.debug输出日志到控制台,但是写日志文件就没那么顺利了,一直不成功,找了N种配置,以下配置方法可行 首先确保已引 ...

  6. 在docker上部署centos

    1.查找镜像源$ docker search centosNAME DESCRIPTION STARS OFFICIALcentos The official build of CentOS. 385 ...

  7. 数据库Dao层编增删改查写,数据库事务,数据库升级

    数据库事务 有两个特点 1.安全性 情景:正常的转账行为,这个时候如果出现停电等异常,已经扣钱但是没有加钱:这个时候就可用数据库事务解决问题 2.高效性: 使用数据库事务添加享受同数量的数据,对比耗时 ...

  8. linux-安装、启动nginx

    1.下载安装pcre库 pcre是一个正则表达式库,nginx的rewrite模块需要依赖该库. 下载地址:http://www.pcre.org/ wget https://ftp.pcre.org ...

  9. java多线程之wait和notify协作,生产者和消费者

    这篇直接贴代码了 package cn.javaBase.study_thread1; class Source { public static int num = 0; //假设这是馒头的数量 } ...

  10. Spark 中 GroupByKey 相对于 combineByKey, reduceByKey, foldByKey 的优缺点

    避免使用GroupByKey 我们看一下两种计算word counts 的方法,一个使用reduceByKey,另一个使用 groupByKey: val words = Array("on ...