• 欢迎访问废江's博客 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏本站吧

Exhaustive Search

AOJ 站点默认 10个月前 (04-11) 433次浏览 已收录 14个评论
文章目录[隐藏]

Question

Write a program which reads a sequence A of n elements and an integer M, and outputs “yes” if you can make M by adding elements in A, otherwise “no”. You can use an element only once.

You are given the sequence A and q questions where each question contains Mi.

Input
In the first line n is given. In the second line, n integers are given. In the third line q is given. Then, in the fourth line, q integers (Mi) are given.

Output
For each question Mi, print yes or no.

Constraints
n ≤ 20
q ≤ 200
1 ≤ elements in A ≤ 2000
1 ≤ Mi ≤ 2000
Sample Input 1
5
1 5 7 10 21
8
2 4 17 8 22 21 100 35
Sample Output 1
no
no
yes
yes
yes
yes
no
no

Meaning


从数组A中需拿出任意几个元素相加判断是否能得到给定的值Mi,如果可以输出yes,否则输出no

Sloution

首先,题目中的值n很小,那就直接递归给所有值全部列出来吧,也只是2的n次方。

Coding

Summary


递归函数中重复调用了两个递归函数,算法复杂度为0(2的n次方)。。。

个人博客 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Exhaustive Search
喜欢 (0)
[]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到
(14)个小伙伴在吐槽
  1. Hello. In my opinion you are mistaken. I can prove it.
    video2021-01-20 09:59 (3天前)回复 Windows 7 | Firefox浏览器 4.0
  2. Nice post keep on sharing new things.
    آهنگ2021-01-18 15:12 (5天前)回复 Windows 7 | Firefox浏览器 4.0
  3. The information you have provided in this article is very significant.
    anita2021-01-18 12:49 (5天前)回复 Windows 7 | Firefox浏览器 4.0
  4. Thank for your writting! I have read through some similar topics! However, your article gave me a very special impression, unlike other articles. I hope you continue to have valuable articles like this or more to share with everyone!
    clip2021-01-18 09:24 (5天前)回复 Windows 7 | Firefox浏览器 4.0
  5. treatment for erectile dysfunction cheap rx canadian pharmacy viagra
    匿名2021-01-14 00:44 回复 Windows 7 | Firefox浏览器 31.0
  6. rx plus pharmacy pharmacy rx one reviews best drugstore foundation
    匿名2021-01-11 18:08 回复 Windows 10 | Chrome 63.0.3239.84
  7. online pharmacies canadian drug pharmacy indian pharmacy online
    匿名2021-01-11 01:06 回复 Windows 10 | Firefox浏览器 57.0
  8. pharm pharmacy online drugstore canada pharmacy
    匿名2021-01-10 17:04 回复 Windows 10 | Chrome 62.0.3202.94
  9. online pharmacies best drugstore setting spray best drugstore lipstick
    匿名2021-01-10 04:14 回复 Windows 8.1 | Chrome 63.0.3239.84
  10. best ed medication online drugstore e d
    匿名2021-01-10 02:31 回复 Windows XP | Firefox浏览器 44.0
  11. drugs from canada mens ed pills best drugstore primer
    匿名2021-01-09 13:06 回复 未知操作系统 | Firefox浏览器 32.1
  12. You have a quality site, I congratulate you on this
    匿名2021-01-03 08:14 回复 Windows 10 | Chrome 62.0.3202.94
  13. wallmart price viagra brand viagra with dapoxetine viagra in australia
    匿名2020-12-24 12:37 回复 Windows 10 | Firefox浏览器 57.0
  14. There is no way to quantify the immense popularity enjoyed by the sport of soccer in countries the world over. Jerrine Hansiain Chema
    recep ivedik2020-12-10 14:08 回复 Windows 10 | Chrome 86.0.4240.193