NYOJ--927--dfs--The partial sum problem
/*
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的更多相关文章
- NYOJ 927 The partial sum problem 【DFS】+【剪枝】
The partial sum problem 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描写叙述 One day,Tom's girlfriend give him a ...
- The partial sum problem
算法:搜索 描述 One day,Tom's girlfriend give him an array A which contains N integers and asked him:Can yo ...
- 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 ...
- NYoj The partial sum problem(简单深搜+优化)
题目链接:http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=927 代码: #include <stdio.h> #include & ...
- 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 ...
- 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 ...
- 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 ...
- Subset sum problem
https://en.wikipedia.org/wiki/Subset_sum_problem In computer science, the subset sum problem is an i ...
- 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 ...
随机推荐
- Let's Encrypt 免费SSL证书
Let's Encrypt免费又好用的证书,废话不多说. 假设我的域名为:163.org 1.克隆代码 git clone https://github.com/letsencrypt/le ...
- 让textarea和附近的文字居中对齐
textarea {display:inline-block;vertical-align:middle;}
- [leetcode-624-Maximum Distance in Arrays]
Given m arrays, and each array is sorted in ascending order. Now you can pick up two integers from t ...
- PGI Compiler for OpenACC Output Syntax Highlighting
PGI Compiler for OpenACC Output Syntax Highlighting When use the PGI compiler to compile codes with ...
- Azure MySQL PaaS (3) 创建MySQL异地只读数据库 (Master-Slave)
<Windows Azure Platform 系列文章目录> Azure MySQL PaaS服务提供异地只读的功能,我们可以在主站点,比如Azure上海数据中心,创建MySQL主节点. ...
- MyBatis源码解析【2】构建项目
有了之前的准备,今天就要开始构建学习使用的项目了.废话不多说.开始吧. 首先我用IDEA构建了一个空的maven项目,然后加入了Mybatis的依赖. <dependencies> < ...
- Vue 实际项目中你可能会遇见的坑
纸上得来终觉浅,绝知此事要躬行! Vue的文档和教程看的太多,小的demo做的多,也不如自己实际的进行一个完整项目的开发.只有做了才知道原来问题这么多,这里列举了一些你做demo教程可能不会遇见的坑. ...
- eclipse 设置 默认编码为 utf-8
学习javaweb时,开发工具都采用utf-8的编码方式,给eclipse设置默认编码为utf-8的编码方法 菜单 Window -> preference -> General -> ...
- Java探秘之神秘的字符串String(二)
不可变性 String可以说是最常用的类型了,即字符串类型,String是常量(final关键词修饰的),他的值不能被创建后更改,因为字符串是不可被改变的,所以可以被用来共享. Java语言为Stri ...
- 野村证券伦敦分部面试 - Java岗位
第一轮 1. 笔试 30 mins 一共六道大题,前两题有4-5个小题. 第一道大题主要是考察Java Collections: a. LinkedList和ArrayList的区别 b. Set和L ...