题目链接:http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=927

代码:

 #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <iostream>
using namespace std; int n,k;
int a[];
int sum=;
bool v[]; int DFS(int sum,int m)
{
if(sum==k)
{
return ;
}
for(int j=m;j<n;j++)
{
v[j]=true;
if(DFS(sum+a[j],j+)) return ;//要深刻理解这个递归
v[j]=false;
}
return ;
} int main()
{
while(~scanf("%d",&n)){
for(int i=;i<n;i++){
scanf("%d",&a[i]);
}
scanf("%d",&k);
if(DFS(,))
printf("Of course,I can!\n");
else
printf("Sorry,I can't!\n");
}
}

NYoj 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. NYOJ--927--dfs--The partial sum problem

    /* Name: NYOJ--927--The partial sum problem Author: shen_渊 Date: 15/04/17 19:41 Description: DFS,和 N ...

  3. 简单深搜:POJ1546——Sum it up

    结束了三分搜索的旅程 我开始迈入深搜的大坑.. 首先是一道比较基础的深搜题目(还是很难理解好么) POJ 1564 SUM IT UP 大体上的思路无非是通过深搜来进行穷举.匹配 为了能更好地理解深搜 ...

  4. POJ 2386 Lake Counting (简单深搜)

    Description Due to recent rains, water has pooled in various places in Farmer John's field, which is ...

  5. 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 ...

  6. HDOJ1015(简单深搜)

    Safecracker Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  7. hdoj-1016-Prime Ring Problem【深搜】

    Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...

  8. 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 ...

  9. The partial sum problem

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

随机推荐

  1. 警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context}

    警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to'org.eclipse ...

  2. effective c++ prefer const,enum, inline to #defines

    学习心得 对于纯常量,最好以const对象或者enums替换#define #define FIRST 3 //not good enum { first=1, second=2 } ; int nu ...

  3. cocos2dx 遮罩层 android 手机上 失败

    1.CCClippingNode使用(在模拟器上ok,在手机上不行),实现多个剪切区域 local layer=CCLayerColor:create(ccc4(0,0,0,110))     --/ ...

  4. Java equals的一个坑

    public class StringEqualsObject { public static void main(String[] args) { String name="Tom&quo ...

  5. JSON.stringify 语法解释

    行为:此函数的作用主要是串行化对象. 或许有些人是过敏的字系列.我非常理解easy.是对象的类型转换成字符串类型(或者更确切的说是json类型的).就这么简单.打个例如说,你有一个类,那么你能够通过这 ...

  6. CentOS构造SNMP

    <span style="font-size:14px;">本文介绍怎样在CentOS环境下配置一个简单的SNMP服务</span> 软件安装 切换到系统管 ...

  7. 系列二VS项目软件配置工具介绍

    原文:系列二VS项目软件配置工具介绍 Svn和VisualSvn介绍 在使用TortoiseSvn(SVN客户端)+ AnkhSvn(VS2008插件) +VisualSvn Server(版本控制服 ...

  8. 二维码简单Demo

    二维码简单Demo 一.视图 @{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name=&qu ...

  9. WWDC 2014 Session 205/217 Extension 注意事项

    基于阅读下面的内容205和217的PDF做笔记.没有深入研究. 205 Creating Extensions for iOS and OS X, Part 1 217 Creating Extens ...

  10. Serializable 作用

    Serializable 作用 序列化的attribute,是为了利用序列化的技术 准备用于序列化的对象必须设置 [System.Serializable] 标签,该标签指示一个类能够序列化. 便于在 ...