dfs判重

#include<stdio.h>
#include<iostream>
#include<cstdio>
#include<queue>
#include<queue>
#include<stack>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<climits>
#include<algorithm>
using namespace std;
#define ll unsinged long long
#define PI acos(-1.0)
#define ING 0x7fffffff
#define INF 0x3f3f3f3f
#define mod 1000000007
#define mod 5201314
#define N 1005
int n,m;
int a[N];
int d[N];
int flag;
void dfs(int x,int sum,int num)
{
if(sum>n)
return;
if(sum==n)
{
flag=1;
printf("%d",d[0]);
for(int i=1;i<num;i++)
{
printf("+%d",d[i]);
}
printf("\n");
return;
}
for(int i=x;i<m;i++)
{
d[num]=a[i];
dfs(i+1,sum+a[i],num+1);
while(a[i+1]==a[i])//判重
i+=1;
}
}
int main()
{
while(~scanf("%d%d",&n,&m)&&n&&m)
{
for(int i=0;i<m;i++)
{
scanf("%d",&a[i]);
}
printf("Sums of %d:\n",n);
flag=0;
dfs(0,0,0);
if(flag==0)
printf("NONE\n");
}
return 0;
}

poj1564的更多相关文章

  1. poj1564 Sum It Up dfs水题

    题目描述: Description Given a specified total t and a list of n integers, find all distinct sums using n ...

  2. poj1564 Sum it up

    题目链接: http://poj.org/problem?id=1564 题目: Sum It Up Time Limit: 1000MS   Memory Limit: 10000K Total S ...

  3. POJ-1564 dfs

    #include"cstring" #include"cstdio" +; int nux[maxn]; int nua[maxn];//解的集合 int t; ...

  4. poj1564 Sum It Up (zoj 1711 hdu 1258) DFS

    POJhttp://poj.org/problem?id=1564 ZOJhttp://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=711 ...

  5. DFS系列 POJ(自认为的讲解)

    C - Sum It Up POJ1564 题意: 给你一个N,然后给你一堆数The numbers in each list appear in nonincreasing order, and t ...

随机推荐

  1. BZOJ 2809 APIO 2012 dispatching 平衡树启示式合并

    题目大意:给出一棵树,每个节点有两个值,各自是这个忍者的薪水和忍者的领导力.客户的惬意程度是这个点的领导力乘可以取得人数.前提是取的人的薪水总和不超过总的钱数. 思路:仅仅能在子树中操作.贪心的想,我 ...

  2. SolidEdge 如何绘制断裂剖视图 局部剖视图

    1 点击局部放大图,然后点击绘制按钮,然后点击选择要绘制的视图   2 绘制封闭的局部剖视图的剖面线(必须封闭,点击最后一个点封闭之后会变成蓝色虚线)   3 修改深度(不一定要在下图的右下角修改深度 ...

  3. IOS UIPickView+sqlite 选择中国全部城市案例

    1.案例简单介绍 通过读取文件.将中国全部城市写入sqlite数据库中,现通过UIPickView实现中国全部城市的选择,效果图例如以下所看到的 2.城市对象模型 中国全部城市数据请看http://b ...

  4. 解决ionic 上拉加载组件 ion-infinite-scroll自动调用多次的问题或禁止第一次加载

    ionic 中一个上拉刷新的组件 ion-infinite-scroll,如果页面未填充满页面高度,会自动检测并无限调用多次加载更多的函数: 当然,主要会导致首次调用的时候,会执行几次加载更多的函数: ...

  5. android_checkbox_dialog 设计 是不是要开起 默认不提示对话框

    android_checkbox_dialog设计是不是开起默认不提示 package com.example.android_checkbox_dialog; import android.app. ...

  6. poj 3169 Layout(差分约束)

    Layout Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6549   Accepted: 3168 Descriptio ...

  7. eclipse 配置执行hadoop 2.7 程序样例參考步骤

    前提:你搭建好了hadoop 2.x的linux环境,并可以成功执行.还有就是window可以訪问到集群.over 1. hfds-site.xml 添加属性:关闭集群的权限校验.windows的用户 ...

  8. phpExcel大数据量情况下内存溢出解决

    版本:1.7.6+ 在不进行特殊设置的情况下,phpExcel将读取的单元格信息保存在内存中,我们可以通过 PHPExcel_Settings::setCacheStorageMethod() 来设置 ...

  9. linux 输入子系统(4) intput_dev 接口描述

    Name struct input_dev - represents an input device Synopsis struct input_dev { const char * name; // ...

  10. PPAPI与Browser间使用AsyncIPC通信

    採用AsyncIpc这个项目(https://github.com/hicdre/AsyncIpc).来完毕PPAPI Plugin进程与Browser进程的通信. foruok原创.如需转载请关注f ...