HDU 1258 Sum It Up (DFS)
Sum It Up
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2982 Accepted Submission(s): 1493
5 3 2 1 1
400 12 50 50 50 50 50 50 25 25 25 25 25 25
0 0
4
3+1
2+2
2+1+1
Sums of 5:
NONE
Sums of 400:
50+50+50+50+50+50+25+25+25+25
50+50+50+50+50+25+25+25+25+25+25
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm> using namespace std; int n,k,a[],flag,res[]; void DFS(int cur,int sum,int cnt){
if(sum>n)
return ;
if(sum==n){
printf("%d",res[]);
for(int i=;i<cnt;i++)
printf("+%d",res[i]);
printf("\n");
flag=;
}
for(int i=cur;i<k;i++){
res[cnt]=a[i];
DFS(i+,sum+a[i],cnt+);
while(i+<k && a[i]==a[i+]) //去除相同的分解式
i++;
}
} int main(){ //freopen("input.txt","r",stdin); while(~scanf("%d%d",&n,&k) && n){
for(int i=;i<k;i++)
scanf("%d",&a[i]);
printf("Sums of %d:\n",n);
flag=;
DFS(,,);
if(!flag)
printf("NONE\n");
}
return ;
}
HDU 1258 Sum It Up (DFS)的更多相关文章
- hdu 1258 Sum It Up(dfs+去重)
题目大意: 给你一个总和(total)和一列(list)整数,共n个整数,要求用这些整数相加,使相加的结果等于total,找出所有不相同的拼凑方法. 例如,total = 4,n = 6,list = ...
- HDU 1258 Sum It Up(dfs 巧妙去重)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1258 Sum It Up Time Limit: 2000/1000 MS (Java/Others) ...
- hdu 1258 Sum It Up (dfs+路径记录)
pid=1258">Sum It Up Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- HDU 2553 N皇后问题(dfs)
N皇后问题 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Description 在 ...
- POJ 1564(HDU 1258 ZOJ 1711) Sum It Up(DFS)
题目链接:http://poj.org/problem?id=1564 题目大意:给定一个整数t,和n个元素组成的集合.求能否用该集合中的元素和表示该整数,如果可以输出所有可行解.1<=n< ...
- hdu 1016 Prime Ring Problem(dfs)
Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- hdu 5423 Rikka with Tree(dfs)bestcoder #53 div2 1002
题意: 输入一棵树,判断这棵树在以节点1为根节点时,是否是一棵特殊的树. 相关定义: 1. 定义f[A, i]为树A上节点i到节点1的距离,父节点与子节点之间的距离为1. 2. 对于树A与树B,如 ...
- HDU 1312 Red and Black (dfs)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1312 Red and Black Time Limit: 2000/1000 MS (Java/Oth ...
- hdu 5423 Rikka with Tree(dfs)
Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...
随机推荐
- Spark简介及其在ubuntu下的安装使用
转:http://blog.csdn.net/pelick/article/details/9888311 Spark概述 Spark是一种与 Hadoop 相似的开源集群计算环境,在性能和迭代计算上 ...
- Cognos11中ActiveReport在移动端的应用
一.环境准备 1.1:前提准备 需要安装了cognos server11,并且已经配置好了服务端 IBM Cognos 版本:IBM Cognos Analytics 11.0.6 IBM Cogno ...
- unity3d内存管理坑爹之处
Resources.UnloadUnusedAssets();会卸载没有引用的资源,切场景也会自动清理 但是注意,如果不调,是不会自动清理的,比如不断的用www加载图片资源,即使没有引用,也一样在内存 ...
- oauth2-server-php-docs 授权控制器
授权控制器 概观 对于授权端点,要求用户使用authorization code(授权码授权类型)或access token(隐式授权类型)对客户端进行认证和重定向. 方法 handleAuthori ...
- Log4j日志体系结构
转自:https://my.oschina.net/andylucc/blog/794867 摘要 我们在写日志的时候首先要获取logger,在每一个使用log4j的项目都有很多个地方要获取logge ...
- 获取sevlet response值
调用: PrintWriter out = new PrintWriter(new OutputStreamWriter(response.getOutputStream(), "UTF-8 ...
- 微信小程序 - 接口更新记录以及解决方案(2018/12/26)
2018/8/17 - 背景音频需要在app.json添加requireBackGroundModes 2018/9/12 - 微信更改获取用户信息接口/获取位置等接口 - button 2018/1 ...
- 通过实例看懂diff命令输出
摘自:http://blog.sina.com.cn/s/blog_612144f30100nkpt.html ############################### 实例: 有这样两个文件: ...
- 转:nginx模块开发——handler(一)
handler模块简介 相信大家在看了前一章的模块概述以后,都对nginx的模块有了一个基本的认识.基本上作为第三方开发者最可能开发的就是三种类型的模块,即handler,filter和load-ba ...
- JavaWeb项目配置化之Properties类的使用
转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6397370.html 在项目中的应用见: https://github.com/ygj0930/Couple ...