2016年武汉科技大学邀请赛网络赛 F题

来源:互联网 发布:天津网络推广公司 编辑:程序博客网 时间:2024/06/10 22:28

A Stones Game

Time Limit: 1 Sec  Memory Limit: 128 MB   64bit IO Format: %lld
Submitted: 13  Accepted: 2
[Submit][Status][Web Board]

Description

Alice and Bob are playing a stones picking game. The rules of the game is like this: some indentical stones, total n, every time the player can only pick the stones of the number a, which is one of A1 - Am sequence. The one who takes the last stone will win the game! Alice plays first. Alice wants to know whether there is a winning strategy, if yes output  the number for the first step, otherwise output "No".

Input

Each test case has two lines.

The first line contain two integer n and m (1<=n<=1e9,1<=m<=10).

The second line contains m integers A1, A2, ..., Am, each integer is in the range of [1, 10].

Output

Output a single integer — If there exists a answer output it (if there are multiple solutions output the minimum); Otherwise output "No".

Sample Input

17 31 2 4

Sample Output

2

HINT

We should find that there could be a state that none of them will win. For exmaple, if there are 7 stones, each one could only take two stones for a time. They could not take the last stone forever. Then, none of them will be the winner.


题目意思:n堆石子,每一次每个人可以选择m个数中的一个数,拿走对应数量石子的胜。问第一步走什么保证有必胜策略。


题解:可以注意到这些数字非常小。所以每一步的状态之多和前10步的状态有关。那么至多经过(3^10)步就会面临之前相同的情况,这样救有了循环。利用循环节加速中间过程即可。
注意有一种情况双方都没有必胜策略。

0 0
原创粉丝点击