#include"cstring"
#include"cstdio"
const int maxn=+;
int nux[maxn];
int nua[maxn];//解的集合
int t;//t为和
int n;//n为元素个数
bool flag;//判断是否有解
void dfs(int sum,int cur,int k){//sum剩余的大小 k为下标,cur为元素个数
if(sum==){
flag=false;//证明有解
for(int i=;i<cur;i++)
if(i==)
printf("%d",nua[i]);
else
printf("+%d",nua[i]);
printf("\n");
return;
}
for(int i=k;i<n;i++){
if(i==k||nux[i]!=nux[i-]&&sum>=nux[i]){//判断是否重叠
nua[cur]=nux[i];
dfs(sum-nux[i],cur+,i+);
}
}
}
int main(){
while(scanf("%d%d",&t,&n)!=EOF){
if(n==&&t==) break;
for(int i=;i<n;i++){
scanf("%d",&nux[i]);
}
flag=true;
printf("Sums of %d:\n", t);
dfs(t,,);
if(flag)
printf("NONE\n");
}
return ;
}

POJ-1564 dfs的更多相关文章

  1. POJ 1564 经典dfs

    1.POJ 1564 Sum It Up 2.总结: 题意:在n个数里输出所有相加为t的情况. #include<iostream> #include<cstring> #in ...

  2. poj 1564 Sum It Up (DFS+ 去重+排序)

    http://poj.org/problem?id=1564 该题运用DFS但是要注意去重,不能输出重复的答案 两种去重方式代码中有标出 第一种if(a[i]!=a[i-1])意思是如果这个数a[i] ...

  3. POJ 1564(HDU 1258 ZOJ 1711) Sum It Up(DFS)

    题目链接:http://poj.org/problem?id=1564 题目大意:给定一个整数t,和n个元素组成的集合.求能否用该集合中的元素和表示该整数,如果可以输出所有可行解.1<=n< ...

  4. poj 1564 Sum It Up | zoj 1711 | hdu 1548 (dfs + 剪枝 or 判重)

    Sum It Up Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Sub ...

  5. poj 1564 Sum It Up【dfs+去重】

    Sum It Up Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6682   Accepted: 3475 Descrip ...

  6. POJ 1564 Sum It Up(DFS)

    Sum It Up Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit St ...

  7. POJ 1564 Sum It Up (DFS+剪枝)

                                                                                                       ...

  8. Sum It Up POJ 1564 HDU 杭电1258【DFS】

    Problem Description Given a specified total t and a list of n integers, find all distinct sums using ...

  9. poj 1564 Sum It Up(dfs)

    Sum It Up Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7191   Accepted: 3745 Descrip ...

  10. poj 1564 Sum It Up

    题目连接 http://poj.org/problem?id=1564 Sum It Up Description Given a specified total t and a list of n ...

随机推荐

  1. React Native安装步骤

    先贴出中文网安装指南:http://reactnative.cn/docs/0.46/getting-started.html 本文会点出一些安装时遇到的坑,和解决方案! 1.首先是安装Chocola ...

  2. python 上传文件下载图片

    python 2.7 poster-0.8.1 requests-2.7.0 #coding:utf-8import urllibimport urllib2import sysimport time ...

  3. Android 热门技术干货

    http://mp.weixin.qq.com/s?__biz=MzIwMzYwMTk1NA==&mid=2247484939&idx=1&sn=d1871b09de55ca6 ...

  4. Solr6.5与mysql集成建立索引

    首先在solrconfig.xml(我的是保存在/usr/local/tomcat/solrhome/mycore/conf/下)的<requestHandler name="/sel ...

  5. Netty聊天室(2):从0开始实战100w级流量应用

    目录 客户端 Client 登录和响应处理 写在前面 客户端的会话管理 客户端的逻辑构成 连接服务器与Session 的创建 Session和 channel 相互绑定 AttributeMap接口的 ...

  6. 【python】-- RabbitMQ RPC模型

    RabbitMQ RPC模型 RPC(remote procedure call)模型说通俗一点就是客户端发一个请求给远程服务端,让它去执行,然后服务端端再把执行的结果再返回给客户端. 1.服务端 i ...

  7. HDOJ 3473 Minimum Sum

    划分树,统计每层移到左边的数的和. Minimum Sum Time Limit: 16000/8000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  8. Smarty模板的逻辑运算符号稍微做一下总结

    对Smarty模板的逻辑运算符号稍微做一下总结,以备后用. eq    equal : 相等neq    not equal:不等于gt    greater than:大于lt    less th ...

  9. Android SDK上手指南 3:用户交互

    在这篇教程中,我们将对之前所添加的Button元素进行设置以实现对用户点击的检测与响应.为了达成这一目标,我们需要在应用程序的主Activity类中略微涉及Java编程内容.如果大家在Java开发方面 ...

  10. java入门了解11

    1.码表 (一)码表种类 ASCII:美国标准信息交换码,用一个字节的7位可以表示 ISO8859-1:拉丁码表.欧洲码表,用一个字节的8位表示,对ASCII没用到空间补充了自己特有的 GB2312: ...