zoukankan      html  css  js  c++  java
  • 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
    ");
            else
                printf("No
    ");
        }
        return 0;
    }

    版权声明:本文为博主原创文章,未经博主允许不得转载。http://xiang578.top/

  • 相关阅读:
    !function() {}()
    element.dataset API
    正则匹配 数字和英文状态下的逗号
    《vim实用技巧》读书笔记
    ajax分页
    smarty分页类
    数组排序
    数组大类
    自动刷新价格
    简单购物车
  • 原文地址:https://www.cnblogs.com/xryz/p/4847949.html
Copyright © 2011-2022 走看看