第九届北京化工大学程序设计竞赛网络同步赛 A (搜索)
来源:互联网 发布:淘宝店家加微信发红包 编辑:程序博客网 时间:2024/04/27 22:59
题解
直接搜索,输入时候记录一下前缀和,然后搜到当前这个数,后面的数加起来都小于需要的话就直接返回
代码
#include <cstdio>#include <queue>#include <cstring>#include <iostream>#include <cstdlib>#include <algorithm>#include <vector>#include <map>#include <string>#include <set>#include <ctime>#include <cmath>#include <cctype>using namespace std;#define maxn 1005#define LL long longint n,m,a[maxn];int sum[maxn];int flag;void dfs(int pos,int y){ if (y==n) flag=1; if (flag) return; if (y+sum[m]-sum[pos-1] <n || pos>m || y>n) return; dfs(pos+1,y+a[pos]); dfs(pos+1,y);}int cas=1,T;int main(){ while (scanf("%d%d",&m,&n)!=EOF) { sum[0]=0; for (int i = 1;i<=m;i++) { scanf("%d",&a[i]); sum[i]=sum[i-1]+a[i]; } flag = 0; dfs(1,0); if (flag == 0) printf("No\n"); else printf("Yes\n"); } return 0;}
题目
A - A Math game
Time Limit: 2000/1000MS (Java/Others) Memory Limit: 256000/128000KB (Java/Others)
Problem Description
Recently, Losanto find an interesting Math game. The rule is simple: Tell you a number H, and you can choose some numbers from a set {a[1],a[2],……,a[n]}.If the sum of the number you choose is H, then you win. Losanto just want to know whether he can win the game.
Input
There are several cases.
In each case, there are two numbers in the first line n (the size of the set) and H. The second line has n numbers {a[1],a[2],……,a[n]}.0
Output
If Losanto could win the game, output “Yes” in a line. Else output “No” in a line.
Sample Input
10 87
2 3 4 5 7 9 10 11 12 13
10 38
2 3 4 5 7 9 10 11 12 13
Sample Output
No
Yes
- 第九届北京化工大学程序设计竞赛网络同步赛 A (搜索)
- 第九届北京化工大学程序设计竞赛网络同步赛 A
- 第九届北京化工大学程序设计竞赛网络同步赛
- 第九届北京化工大学程序设计竞赛(部分题解)
- 第九届北京化工大学程序设计竞赛训练总结【7/10】
- ACdream-1734 Can you make a water problem?【模拟排序贪心】 第九届北京化工大学程序设计竞赛
- 北京化工大学 程序设计实训(报告)
- 安徽大学第九届大学生程序设计竞赛 网络预选赛 A
- 师创杯”山东理工大学第九届ACM程序设计竞赛(网络同步赛)--I皮卡丘的梦想2
- 第四届“图灵杯”NEUQ-ACM程序设计竞赛(团队赛)-网络同步赛A(组合数学)
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛-A-Visiting Peking University
- 第十五届北京师范大学程序设计竞赛决赛(网络同步赛)
- 第十五届北京师范大学程序设计竞赛决赛(网络同步赛)
- 第十五届北京师范大学程序设计竞赛决赛(网络同步赛)
- 第十五届北京师范大学程序设计竞赛决赛(网络同步赛)
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2015)网络赛 1007 Boxs(状态压缩+搜索)
- 第十一届北京师范大学程序设计竞赛(网络同步赛)+A. BNU ACM校队时间安排表
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛 - C A Simple Job (模拟)(multiset)
- java中时间、日历及时间格式化汇总
- yii2安装
- Smith Numbers(Poj1142)(质因数分解+素数判定)
- java中的构造器与普通函数的区别
- 南邮编程在线编程题二十二:判断矩阵是否对称
- 第九届北京化工大学程序设计竞赛网络同步赛 A (搜索)
- (解题报告)HDU1061---Rightmost Digit
- iptomac 非snmp的无奈之法,也很有用
- ios Mantle使用小记
- python中的列表的复制
- 双链表的建立
- 【See you】
- 随意贴一段任意进制转十进制的代码
- 编程粒度