POJ-1564 dfs
#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的更多相关文章
- POJ 1564 经典dfs
1.POJ 1564 Sum It Up 2.总结: 题意:在n个数里输出所有相加为t的情况. #include<iostream> #include<cstring> #in ...
- poj 1564 Sum It Up (DFS+ 去重+排序)
http://poj.org/problem?id=1564 该题运用DFS但是要注意去重,不能输出重复的答案 两种去重方式代码中有标出 第一种if(a[i]!=a[i-1])意思是如果这个数a[i] ...
- POJ 1564(HDU 1258 ZOJ 1711) Sum It Up(DFS)
题目链接:http://poj.org/problem?id=1564 题目大意:给定一个整数t,和n个元素组成的集合.求能否用该集合中的元素和表示该整数,如果可以输出所有可行解.1<=n< ...
- 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 ...
- poj 1564 Sum It Up【dfs+去重】
Sum It Up Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6682 Accepted: 3475 Descrip ...
- POJ 1564 Sum It Up(DFS)
Sum It Up Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit St ...
- POJ 1564 Sum It Up (DFS+剪枝)
...
- 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 ...
- poj 1564 Sum It Up(dfs)
Sum It Up Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7191 Accepted: 3745 Descrip ...
- 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 ...
随机推荐
- ASIHTTPRequest中文入门教程全集 http://www.zpluz.com/thread-3284-1-1.html
本文转载至 目录 3 第 1 章 创建和运行请求 5 1.1. 创建一个同步请求 5 1.2. 创建一个异步请求 5 1.3. 使用程序块(blocks ) 6 1.4. 使用 ...
- Sum of Remainders(数学题)
F - Sum of Remainders Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I ...
- (比赛)B - 棋盘问题(dfs)
B - 棋盘问题 Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%lld & %llu Practice POJ ...
- 九度OJ 1323:World Cup Betting(世界杯) (基础题)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:492 解决:219 题目描述: With the 2010 FIFA World Cup running, football fans th ...
- jvm的字符串池
1 jvm中是有专门的字符串池的内存空间的,这块空间和栈和堆不同. 2 String s = "string constant"; 这个时候,如果string pool中没有&qu ...
- vue前戏ES6
es6语法 es6语法:let和const: { var a=123; let b=234; } console.log(a); console.log(b); 浏览器里会只看到123; 而且还会抱一 ...
- Django安装debug tool bar
1.安装Django Debug Toolbarpip install django-debug-toolbar 2.设置项目的DEBUG属性DEBUG = True 3.INSTALLED_APPS ...
- Android LockScreen (锁屏弹窗)
在要弹窗的Activity需要进行以下设置,才可以在锁屏状态下弹窗 @Override protected void onCreate(Bundle savedInstanceState) { fin ...
- linux 中sort命令 按照指定列排序
sort怎样按指定的列排序0000 27189 41925425065f 15 419254250663 7 419254250675 5 419254250691 76 419254250693 2 ...
- Python程序打包成exe的一些坑
今天写了一个项目,Python项目,需要在win7上跑起来,我想,这不是简单的不行么,直接上Pyinstaller不就完了? 但是后来,我发觉我真是too young too simple. 为什么这 ...