acdream 1726 A Math game
/* ***********************************************
Author :xryz
Email :xiang578@foxmail.com
Created Time :7-11 11:59:34
File Name :2015_07_11.cpp
************************************************ */
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
int a[50],h,n,use[50],sum[50],flag;
void dfs(int x,int cnt)
{
if(cnt==h)
{
flag=1;
return ;
}
if(cnt+sum[x]<h||cnt>h) return ;
if(use[x]==0)
{
use[x]=1;
dfs(x-1,cnt+a[x]);
use[x]=0;
}
dfs(x-1,cnt);
return ;
}
int main()
{
int i;
while(~scanf("%d%d",&n,&h))
{
memset(a,0,sizeof(a));
memset(sum,0,sizeof(sum));
sum[0]=0;
for(i=1; i<=n; i++)
{
scanf("%d",&a[i]);
sum[i]=sum[i-1]+a[i];
}
memset(use,0,sizeof(use));
flag=0;
dfs(n,0);
if(flag==1)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。http://xiang578.top/