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 4 12 3 2
3 3 3
13 3 2
3 3 3

样例输出

YES
YES
NO

题目来源

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

 #include <stdio.h>
int main()
{
int T;
scanf("%d", &T);
while(T--){
int n, m, k;
scanf("%d %d %d", &n, &m, &k);
int a[];
for(int i = ; i < m; i++){
scanf("%d", a+i);
}
int sum = ;
int tmp = ;
while(sum < n && k >= ){
bool flag = false;
for(int i = ; i < m; i++){
if(a[i] && a[i] <= tmp){
sum += a[i];
a[i] = ;
flag = true;
}
}
if(!flag){
sum += tmp;
k--;
}
tmp = sum + ;
}
if(k >= && sum >= n){
puts("YES");
}
else{
puts("NO");
}
}
return ;
}

toj 3616 Add number (没想到啊~~)的更多相关文章

  1. 【原创】这道Java基础题真的有坑!我也没想到还有续集。

    前情回顾 自从我上次发了<这道Java基础题真的有坑!我求求你,认真思考后再回答.>这篇文章后.我通过这样的一个行文结构: 解析了小马哥出的这道题,让大家明白了这题的坑在哪里,这题背后隐藏 ...

  2. 头条编程题 万万没想到之抓捕孔连顺 JavaScript

    [编程题] 万万没想到之抓捕孔连顺 时间限制:1秒 空间限制:131072K 我叫王大锤,是一名特工.我刚刚接到任务:在字节跳动大街进行埋伏,抓捕恐怖分子孔连顺.和我一起行动的还有另外两名特工,我提议 ...

  3. 没想到,Git居然有3种“后悔药”!

    没想到,Git居然有后悔药! 你知道Git版本控制系统中都有哪些"后悔药"吗? 本文通过案例讲解git reset . git revert . git checkout在版本控制 ...

  4. 在做关于NIO TCP编程小案例时遇到无法监听write的问题,没想到只是我的if语句的位置放错了位置,哎,看了半天没看出来

    在做关于NIO TCP编程小案例时遇到无法监听write的问题,没想到只是我的if语句的位置放错了位置,哎,看了半天没看出来 贴下课堂笔记: 在Java中使用NIO进行网络TCP套接字编程主要以下几个 ...

  5. centos clamav杀毒软件安装配置及查杀,没想到linux下病毒比windows还多!

    centos clamav杀毒软件安装配置及查杀,没想到linux下病毒比windows还多! 一.手动安装 1.下载(官网)    cd /soft     wget http://www.clam ...

  6. 杀死众筹的N种方法:没想到山寨大军也参与了

    ​ ​ 众筹作为当下创业者筹集资金,将创意变为现实的最重要手段之一,正面临着越来越多的困难,甚至衍生出杀死众筹的N种方法.甚至这些方法还分为了两类,就众筹本身看,杀死它们的主要方法是:创业者卷钱跑路. ...

  7. 没想到 Google 排名第一的编程语言,为什么会这么火?

    没想到吧,Python 又拿第一了! 在 Google 公布的编程语言流行指数中,Python 依旧是全球范围内最受欢迎的技术语言!   01 为什么 Python 会这么火? 核心还是因为企业需要用 ...

  8. 字节跳动:[编程题]万万没想到之聪明的编辑 Java

    时间限制:1秒 空间限制:32768K 我叫王大锤,是一家出版社的编辑.我负责校对投稿来的英文稿件,这份工作非常烦人,因为每天都要去修正无数的拼写错误.但是,优秀的人总能在平凡的工作中发现真理.我发现 ...

  9. 万万没想到!ModelArts与AppCube组CP了

    摘要:嘘,华为云内部都不知道的秘密玩法,我悄悄告诉您! 双"魔"合璧庆双节 ↑开局一张图,故事全靠编 华为云的一站式开发平台ModelArts和应用魔方AppCube居然能玩到一起 ...

随机推荐

  1. github 删除库

    1.查看库 2.选择想要删除的库,点击setting 3.删除库

  2. 代码审计之CVE-2017-6920 Drupal远程代码执行漏洞学习

     1.背景介绍: CVE-2017-6920是Drupal Core的YAML解析器处理不当所导致的一个远程代码执行漏洞,影响8.x的Drupal Core. Drupal介绍:Drupal 是一个由 ...

  3. window和 linux 在一起 ios和 android在一起 net和js在一起

    step 1: Windows 10 的 Linux Bash 支持「并不是使用虚拟机/模拟器」实现的,而是嵌入一个完整的 Ubuntu Linux 环境.技术上是实时将 Linux 的系统调用转换为 ...

  4. Qt使用QAxObject快速批量读取Excel内容

    网上各种教程用的方法主要是如下这一句: QAxObject * range = worksheet->querySubObject("Cells(int,int)", 1, ...

  5. springboot开发之使用外部servlet容器及对jsp的支持

    一般而言,springboot是使用自己内嵌的servlet容器,比如tomcat等等,而且默认的模板引擎是thymeleaf,那么如何让springboot使用外部的servlet容器并支持对jsp ...

  6. 【学习笔记】Linux基础(二):Linux的基本操作

    二.Linux的基本操作 0.正确的开关机操作 开机和登陆: 安全起见,一般不使用最高权限的root账户登入系统,光立系统时再使用 登录时为login程序提供账户名和密码即可,密码不会被显示,登陆后显 ...

  7. 二、Django学习之增删改查

    增加数据 第一种方式 def index(request): #创建记录方式1 #实例化要添加的记录(对象) student_obj = models.Student( name='dazhuang' ...

  8. LoadIcon的使用

    LoadIcon msdn: Loads the specified icon resource from the executable (.exe) file associated with an ...

  9. data structure test

    1.设计算法,对带头结点的单链表实现就地逆置.并给出单链表的存储结构(数据类型)的定义. #include <iostream> #include <cstdlib> #inc ...

  10. golang学习笔记(二):流程控制

    欢迎访问我的博客和github! 今天咱们把烦人的事情丢一丢,继续来学习go的基础知识. 这篇文章记录go语言的流程控制和更多类型. 流程控制 for Go 只有一种循环结构:for 循环. 基本的 ...