Add number

时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte
总提交: 60 测试通过: 21

描述

Employees of Baidu like to play a game called Making Numbers. It goes like this: there are two players in the game, one is called little A, the other little B. There are some cards with a number on each one of them, little A chooses a number X from 1 to N randomly, while little B has to choose some cards, the sum of which equals X. Now there are already M cards with numbers, and K blank cards. At the beginning of the game, little B is allowed to write numbers on the blank cards. Now little B wants to know, if it is possible to write some numbers that will assure him of the victory, that is to say, if it is possible for him to make up any number from 1 to N with the cards.

输入

The input consists of several test cases. The first line is an integer T,

The first line of each case shows 3 numbers, N M K, the next line follows M numbers that are already written on M cards. 1<=N<=99999999,0<=M<=19,1<=K<=19 and the numbers on M cards are above 0, smaller than or equals N, in non-descending order.

输出

If little B can make it, output "YES", else output "NO".

样例输入

3
15 0 412 3 2
3 3 3
13 3 2
3 3 3

样例输出

YES
YES
NO

题目来源

第四届北京邮电大学程序设计竞赛 2010

 1 #include <stdio.h>
 2 int main()
 3 {
 4     int T;
 5     scanf("%d", &T);
 6     while(T--){
 7         int n, m, k;
 8         scanf("%d %d %d", &n, &m, &k);
 9         int a[100];
10         for(int i = 0; i < m; i++){
11             scanf("%d", a+i);
12         }
13         int sum = 0;
14         int tmp = 1;
15         while(sum < n && k >= 0){
16             bool flag = false;
17             for(int i = 0; i < m; i++){
18                 if(a[i] && a[i] <= tmp){
19                     sum += a[i];
20                     a[i] = 0;
21                     flag = true;
22                 }
23             }
24             if(!flag){
25                 sum += tmp;
26                 k--;
27             }
28             tmp = sum + 1;
29         }
30         if(k >= 0 && sum >= n){
31             puts("YES");
32         }
33         else{
34             puts("NO");
35         }
36     }
37     return 0;
38 }

转载于:https://www.cnblogs.com/luotinghao/p/3411224.html

toj 3616 Add number (没想到啊~~)相关推荐

  1. 用Scrapy爬取分析了7万款App,结果万万没想到!

    作者 | 苏克 来源 | 第2大脑 这是新年的第一篇原创干货. 摘要:使用 Scrapy 爬取豌豆荚全网 70,000+ App,并进行探索性分析. 写在前面:若对数据抓取部分不感兴趣,可以直接下拉到 ...

  2. Python分析了 7 万款 App,万万没想到

    摘要:使用 Scrapy 爬取豌豆荚全网 70,000+ App,并进行探索性分析. 写在前面:若对数据抓取部分不感兴趣,可以直接下拉到数据分析部分. 1 分析背景 之前我们使用了 Scrapy 爬取 ...

  3. Python爬虫新手教程:Python分析了 7 万款 App,万万没想到

    摘要:使用 Scrapy 爬取豌豆荚全网 70,000+ App,并进行探索性分析. 写在前面:若对数据抓取部分不感兴趣,可以直接下拉到数据分析部分. 1 分析背景 之前我们使用了 Scrapy 爬取 ...

  4. Python爬虫新手教程:Python分析了 7 万款 App,万万没想到!

    摘要:使用 Scrapy 爬取豌豆荚全网 70,000+ App,并进行探索性分析. 写在前面:若对数据抓取部分不感兴趣,可以直接下拉到数据分析部分. 1 分析背景 之前我们使用了 Scrapy 爬取 ...

  5. Scrapy 爬取 分析了 7 万款 App,全是没想到

    摘要:使用 Scrapy 爬取豌豆荚全网 70,000+ App,并进行探索性分析. 写在前面:若对数据抓取部分不感兴趣,可以直接下拉到数据分析部分. 1 分析背景 之前我们使用了 Scrapy 爬取 ...

  6. 分析了 7 万款 App,全是没想到

    阅读文本大概需要 10 分钟.   摘要:使用 Scrapy 爬取豌豆荚全网 70,000+ App,并进行探索性    分析.   写在前面:若对数据抓取部分不感兴趣,可以直接下拉到数据分析部    ...

  7. 万万没想到!!! 谷歌面试原来也问ArrayList

    不花时间的导读:这是<好好面试系列>第27篇原创文,该系列主要分享小饭饭面试别人.和被别人面试的经历,该篇文章主要分享ArrayList高频面试题,有兴趣的看看,已经知道的可以无视. 前几 ...

  8. 真没想到,Python还能实现5毛特效

    来源 | ZackSock(ID:ZackSock) 图源 | 视觉中国 Python牛已经不是一天两天的事了,但是我开始也没想到,Python能这么牛.前段时间接触了一个批量抠图的模型库,而后在一些 ...

  9. PyTorch迎来5岁生日,创始人带领大一实习生开发:没想到会这么成功

    点击上方"视学算法",选择加"星标"或"置顶" 重磅干货,第一时间送达 来源丨量子位 编辑丨极市平台 导读 PyTorch公开发布5周年! ...

最新文章

  1. NLP到底有多难?我们笑了,NLP 却忍不住哭了!
  2. 网上找的关于微信开发一些常用代码
  3. 笔记-计算机网络基础-TCP/IP vs OSI
  4. java 08_java 08 权限修饰符 编译运行
  5. 【Ubuntu-Tensorflow】GPU设置及显存资源分配
  6. Codechef Yet another cute girl
  7. kaldi windows安装_kaldi在Windows下的使用
  8. idea分支如何刷新显示最新
  9. python文件输入符_python读入文件时加r的作用?
  10. Docker容器化部署python
  11. android leaks工具,Androidx中ImmLeaksCleaner已经解决了InputMethodManager... - 简书
  12. outlook 让附件在正文中显示 (REF rich リッチ)
  13. 协议森林1——小喇叭开始广播:以太网与WiFi
  14. 江苏计算机编程中小学,编程教育走进小学低年级
  15. 资料:《大学英语》精读第三版(全六册)原文及全文翻译
  16. 利润分配计算机公式,利润与利润分配表计算公式大全
  17. NRF24LE1有源RFID首选
  18. excel合并同一目录下代码(多文件合并到同一个文件多Sheet下、多文件合并到同一个Sheet下)
  19. 5、hibernate第六课
  20. Client requested master to start replication from impossible position; the last event was read from

热门文章

  1. [react] 在React怎么使用Context?
  2. 前端学习(3337):ant design中button按钮尺寸size
  3. Taro+react开发(44)taro基本使用
  4. react学习(43)----react中将一个元素渲染为 DOM
  5. [html] HTML5如何播放ts视频流?
  6. [vue] 在vue事件中传入$event,使用e.target和e.currentTarget有什么区别?
  7. [css] ::first-letter有什么应用场景?
  8. 前端学习(2731):重读vue电商网站41之自定义格式化时间的全局过滤器
  9. 工作118:封装一个带有对话框的button组件
  10. 前端学习(1673):前端系列实战课程之最终封装