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/

  • 相关阅读:
    set-find
    set-equal_range
    set-equal_range
    set-erase
    php 抽象类 静态 单体设计模式
    Servlet 工作原理解析
    职场上一个人情商高的十种表现
    快速学习一门新技术入门
    php中14中排序方式的实现
    php中对Mysql数据库的访问操作
  • 原文地址:https://www.cnblogs.com/xryz/p/4847949.html
Copyright © 2011-2022 走看看