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 ...
随机推荐
- (文档)Shader.Find (在编译时,只包含那些使用中的shader或位置在"Resources"文件夹中shader)
Shader.Find 查找 static function Find (name : string) : Shader Description描述 Finds a shader with the g ...
- Git创建分支/GIT提交分支
git clone xxx.git cd fwspp-react git init touch README.md git add README.md git commit -m "add ...
- mac切换root
方法一: sudo -i sudo su或是su. 转自:http://blog.csdn.net/duanyipeng/article/details/8621967
- IDEA注册码和license服务器附使用方法
以下两种方式均可激活intellij Idea 15和16版本 最上方点击,Help->Registet 1.注册码 43B4A73YYJ-eyJsaWNlbnNlSWQiOiI0M0I0QTc ...
- jQuery 图片裁剪插件 Jcrop
Jcrop是一个jQuery图片裁剪插件,它能为你的WEB应用程序快速简单地提供图片裁剪的功能.特点如下: 对所有图片均unobtrusively(无侵入的,保持DOM简洁) 支持宽高比例锁定 支持 ...
- [Angular CLI] Build application without remove dist folder for Docker Volume
When we develop the Angular app inside Docker container, we can simulate Production envioment by bui ...
- ASP入门(二十一)- 如何自己获取 ADO 连接字符串
1.新建一个文本文件,并将文件名修改为[ado.udl] 注意 如果不显示扩展名,请在资源管理器的[查看 | 选项]对话框中去掉"隐藏已知文件类型的扩展名"勾就可以了. 2.双击这 ...
- Dictionary应用
using System; using System.Collections.Generic; using System.Data; using System.Web; using System.We ...
- 如何设置Apache中的最大连接数
Apache的主要工作模式有两种:prefork和worker 一.两种模式 prefork模式(缺省模式) prefork是Unix平台上的默认(缺省)MPM,使用多个子进程,每个子进程只有一个线程 ...
- VDP
Today VMware announced a new version on their backup product vSphere Data Protection. They gave it t ...