/*
    Name: NYOJ--927--The partial sum problem
    Author: shen_渊
    Date: 15/04/17 19:41
    Description: DFS,和 NYOJ--1058--dfs--部分和问题 基本一致,递归的i+1注意了,其他没什么
*/

#include<cstring>
#include<iostream>
using namespace std;
void dfs(int);
],vis[];
int n,k,sum,flag;
int main()
{
//    freopen("in.txt","r",stdin);
    while(cin>>n){
        memset(vis,,sizeof(vis));
        memset(arr,,sizeof(arr));
        flag = ;
        ; i<n; ++i)cin>>arr[i];
        cin>>k;
        dfs();
        if(flag)cout<<"Of course,I can!\n";
        else cout<<"Sorry,I can't!\n";
    }
    ;
}
void dfs(int ct)
{
    if(sum == k){
        flag = ;
        return ;
    }
    for(int i=ct; i<n; ++i){
        if(sum+arr[i] <= k)
        {
            vis[i] = ;
            sum += arr[i];
            dfs(i+);
            sum -= arr[i];
            vis[i] = ;
            if(flag)return;
        }
    }
}

NYOJ--927--dfs--The partial sum problem的更多相关文章

  1. NYOJ 927 The partial sum problem 【DFS】+【剪枝】

    The partial sum problem 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描写叙述 One day,Tom's girlfriend give him a ...

  2. The partial sum problem

    算法:搜索 描述 One day,Tom's girlfriend give him an array A which contains N integers and asked him:Can yo ...

  3. nyoj 927 The partial sum problem(dfs)

    描述 One day,Tom’s girlfriend give him an array A which contains N integers and asked him:Can you choo ...

  4. NYoj The partial sum problem(简单深搜+优化)

    题目链接:http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=927 代码: #include <stdio.h> #include & ...

  5. ACM题目————The partial sum problem

    描述 One day,Tom’s girlfriend give him an array A which contains N integers and asked him:Can you choo ...

  6. 2017-5-14 湘潭市赛 Partial Sum 给n个数,每次操作选择一个L,一个R,表示区间左右端点,该操作产生的贡献为[L+1,R]的和的绝对值-C。 0<=L<R<=n; 如果选过L,R这两个位置,那么以后选择的L,R都不可以再选择这两个位置。最多操作m次,求可以获得的 最大贡献和。

    Partial Sum Accepted : Submit : Time Limit : MS Memory Limit : KB Partial Sum Bobo has a integer seq ...

  7. summary of k Sum problem and solutions in leetcode

    I found summary of k Sum problem and solutions in leetcode on the Internet. http://www.sigmainfy.com ...

  8. Subset sum problem

    https://en.wikipedia.org/wiki/Subset_sum_problem In computer science, the subset sum problem is an i ...

  9. HDu 1001 Sum Problem 分类: ACM 2015-06-19 23:38 12人阅读 评论(0) 收藏

    Sum Problem Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total ...

随机推荐

  1. PHP中小小的header函数

    不废话,直接说功能 1.重定向,语法: header("location:http://www.lemon-x.ga"); file_put_contents("./te ...

  2. 分布式架构实战--ActiveMQ的安装与使用(单节点)

    具体内容请参考样例代码和视频教程: http://www.roncoo.com/course/view/85d6008fe77c4199b0cdd2885eaeee53 IP:192.168.4.10 ...

  3. Yii 中出现“<?= ... ?>”是什么意思?

    这是php的标签,和<?php ?>一样的.用<?= ?> 就不用echo,否则你要输出的话,需要加上echo词汇输出.这个就是用在模板里面方便点.

  4. java怎么连接mysql数据库

    JDBC(Java Data Base Connectivity,java数据库连接)是一种用于执行SQL语句的Java API,可以为多种关系数据库提供统一访问,它由一组用Java语言编写的类和接口 ...

  5. [Android FrameWork 6.0源码学习] LayoutInflater 类分析

    LayoutInflater是用来解析XML布局文件,然后生成对象的ViewTree的工具类.是这个工具类的存在,才能让我们写起Layout来那么省劲. 我们接下来进去刨析,看看里边的奥秘 //调用i ...

  6. WriteTeacherObj

    package JBJADV003;import java.io.*;public class WriteTeacherObj { /** * @param args */ public static ...

  7. Eclipse 修改 创建的Jsp的默认格式

    Eclipse 的jsp模板修改 打开 eclipse  选择 Window -- Preferences

  8. Oracle,Mysql ,SQL Server 三大数据库带参数的模糊查询, 拼接查询条件问题

    最近项目开发一直在不断切换数据库,有时候一条sql 要同时考虑多种数据库中的兼容问题 , 先总结一条模糊查询拼接查询条件的问题,后续追加总结. 目前使用   mybatis: 1. Oracle 中使 ...

  9. 【亲测】appium_v1.4.16版本自动化适配android7.0系统

    要解决的问题:appium在androidV7.0系统上运行时报错 Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install io.a ...

  10. ISO18000-6B和ISO18000-6C(EPC C1G2)标准的区别

    ISO18000-6B和ISO18000-6C(EPC C1G2)标准的区别 日期:2009-4-2 22:10:26 目前,有两个标准可供选择.一是ISO18000-6B,另一个是已被ISO接纳为I ...