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 ...
随机推荐
- VMware中Linux系统时间与主机同步以及时区设置
网络上有各种资料,但最简单的一种方法就是修改虚拟机的配置文件 *.vmx .修改 tools.syncTime = "FALSE" 为 tools.syncTime = " ...
- PHP把2个二维数组合并一个二维数组
$a = array(0 => Array(id => 66,class_name => www.iiwnet.com),1 => Array(id => 67,clas ...
- JAVA容器结构图
- [leetcode-599-Minimum Index Sum of Two Lists]
Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite ...
- 门控开关项目--整流桥分析,LED限流电阻选择
完整的原理图 常见电阻 常见的精度分为5% 和1%精度,碳膜电阻5%精度,金属膜电阻1%精度. 常见的阻值有 10R, 100R, 330R, 1K, 2K, 3K, 5.1K, 10K, 15K, ...
- Http批量异步发送和数据保存
先说需求. 有个服务程序定时扫描指定文件夹下一个所有文件,文件包含了多个用户(客户)信息及对应的http发送地址和发送数据.现在该服务程序需要提取这些用户信息,然后批量进行发送:发送完后需要将http ...
- android权限(permission)大全
权限添加位置: 权限代码: 1.android.permission.WRITE_USER_DICTIONARY允许应用程序向用户词典中写入新词 2.android.permission.WRITE_ ...
- XML 新手入门基础知识
XML 是可扩展标记语言(Extensible Markup Language)的缩写,其中的 标记(markup)是关键部分.您可以创建内容,然后使用限定标记标记它,从而使每个单词.短语或块成为可识 ...
- JavaScript一个google地图获取
<script type="text/javascript"> /** * 返回一个新创建的<img>元素,该元素用于在获取到地理位置信息后,显示一张Goo ...
- Java 数据类型在实际开发中应用二枚举
在实际编程中,往往存在着这样的"数据集",它们的数值在程序中是稳定的,而且"数据集"中的元素是有限的.在JDK1.5之前,人们用接口来描述这一种数据类型. 1. ...