NYoj The partial sum problem(简单深搜+优化)
题目链接: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(简单深搜+优化)的更多相关文章
- NYOJ 927 The partial sum problem 【DFS】+【剪枝】
The partial sum problem 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描写叙述 One day,Tom's girlfriend give him a ...
- 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 ...
- 简单深搜:POJ1546——Sum it up
结束了三分搜索的旅程 我开始迈入深搜的大坑.. 首先是一道比较基础的深搜题目(还是很难理解好么) POJ 1564 SUM IT UP 大体上的思路无非是通过深搜来进行穷举.匹配 为了能更好地理解深搜 ...
- POJ 2386 Lake Counting (简单深搜)
Description Due to recent rains, water has pooled in various places in Farmer John's field, which is ...
- 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 ...
- HDOJ1015(简单深搜)
Safecracker Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- hdoj-1016-Prime Ring Problem【深搜】
Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 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 ...
- The partial sum problem
算法:搜索 描述 One day,Tom's girlfriend give him an array A which contains N integers and asked him:Can yo ...
随机推荐
- oracle 12c 三学习 pdb 可插拔测试
DECLARE l_result BOOLEAN; BEGIN l_result := DBMS_PDB.check_plug_compatibility( pdb_descr_file => ...
- HDU 4313 Matrix
水题:在一个双连通的树上有一些点很有破坏性,我们要把这些带破环性的点隔开,就是破坏一些边使这些点之间不连通,破坏一条边需要一点时间,问最少需要多少时间(同一时间只能破坏一个地方,且忽略位置转移的时间) ...
- [LeetCode299]Bulls and Cows
题目: You are playing the following Bulls and Cows game with your friend: You write down a number and ...
- JSON小结
在 JSON 中,“Object” 是什么呢? json.org 有很好的解释: 1 .An object is an unordered set of name/value pairs. 2.An ...
- UVA 538 - Balancing Bank Accounts(贪心)
UVA 538 - Balancing Bank Accounts 题目链接 题意:给定一些人的欠钱关系,要求在n-1次内还清钱,问方案 思路:贪心,处理出每一个人最后钱的状态,然后直接每一个人都和最 ...
- 使用hadoop命令rcc生成Record 一个简单的方法来实现自己的定义writable对象
hadoop 的bin文件夹以下一个rcc命令,网上介绍非常少.看了一下源代码.发现能够用来生成 java和c++的hadoop Record 类代码,比起自己直接实现writable 接口.简单非常 ...
- RH033读书笔记(13)-Lab 14 Network Clients
Goal: Practice using a variety of tools to transfer files between your system and a remote system. S ...
- UI设计学习路径(一个)—好酒也怕巷子深
来源 參与米老师对项目的验收的时候.听了老师对UI的看法才注意UI这块内容.非常奇怪为什么我们总是不能注意到本该注意的问题呢?软件开发难道仅仅是功能的实现不包含界面设计吗?当然不是.问题的根源在于我们 ...
- PL/SQL Developer ORA-12154: TNS: 无法解析指定的连接标识符
底: 在这台机器(Win7 64位置 最后)设备Oracle 11g的client(已安装32位ORACLEclient.假设安装64位ORACLEclient的时候,在CMD命令中 ...
- 泛泰A860(高通公司8064 cpu 1080p) 拂4.4中国民营recovery TWRP2.7.1.2文本(通过刷第三版)
专业第三方开发团队 VegaDevTeam (本team 由 syhost suky zhaochengw(z大) xuefy(大星星) tenfar(R大师) loogeo crazyi(天下无雪 ...