Sicily 2682. Die Hard 4

2682. Die Hard 4

Constraints

Time Limit: 1 secs, Memory Limit: 256 MB

Description

In Die Hard with a Vengeance, Simon's strange game of cat and mouse is played. In the park, a time bomb is about to go off. Detective John McClane and his sidekick Zeus must make exactly four gallons from five and three gallon jugs in five minutes. It’s no so easy for them, but finally they solve it in time:
(1) Fill the five gallon jug. Three gallon jug is empty.
(2) Empty three gallons from the five gallon jug into the three gallon jug.
(3) There remains two gallons in the five gallon jug. Empty the three gallon jug.
(4) Pour the two gallons into the three gallon jug.
(5) Fill the five gallon jug and pour one gallon from it into the three gallon jug - filling the three gallon jug.
(6) Four gallons remain in the five gallon jug.
In Die Hard 4, terrorists start another attack. This time, John faces a similar but more difficult problem. Given n jugs of A1, A2, …, An gallons respectively, no weighing scale, to obtain exactly W gallons. Because terrorists no time to prepare all n jugs, so they just ask whether it is possible.

Input

The input consists of multiple datasets. The end of the input is indicated by a line containing a zero.
The format of each dataset is as follows.
n
A1 A2 … An
W
Here, all data items are positive integers. n is the number of jugs (n<=100). A1, A2, …, An (Ai<10^9) are the volume of the jugs. W is the volume they wanted.
 

Output

For each dataset, output the result of the problem in a separate line: “YES” when the problem is solvable, “NO” otherwise.
 

Sample Input

2
3 5
4
2
3 6
4
0

Sample Output

YES
NO

Problem Source

系列热身赛5@2011年上半学期算法考试和4+2选拔赛

// Problem#: 2682
// Submission#: 3556152
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include<cstdio>
int main(){while(1){int N,a,b,t;scanf("%d",&N);if(!N--)break;scanf("%d",&a);while(N--){scanf("%d",&b);while(b){t=a%b;a=b;b=t;}}scanf("%d",&b);printf("%s\n",b%a?"NO":"YES");}return 0;}                                 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值