poj1564
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的更多相关文章
- poj1564 Sum It Up dfs水题
题目描述: Description Given a specified total t and a list of n integers, find all distinct sums using n ...
- poj1564 Sum it up
题目链接: http://poj.org/problem?id=1564 题目: Sum It Up Time Limit: 1000MS Memory Limit: 10000K Total S ...
- POJ-1564 dfs
#include"cstring" #include"cstdio" +; int nux[maxn]; int nua[maxn];//解的集合 int t; ...
- 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 ...
- DFS系列 POJ(自认为的讲解)
C - Sum It Up POJ1564 题意: 给你一个N,然后给你一堆数The numbers in each list appear in nonincreasing order, and t ...
随机推荐
- mybatis 简单项目步骤
mybatis.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configura ...
- 常用shell命令的写法
这并不是教人怎么进行shell编程的文章,只是韦哥在工作中用到的一些简单脚本的写法.因为有些命令即使用过几次了,再次使用时仍然写不对,需要man来看下或者需要google,你也可以理解为对命令的理解不 ...
- 使用脚本删除ios工程中未使用图片
使用脚本删除ios工程中未使用图片 最近在读唐巧大神的<iOS开发进阶>,学到了一个大招:使用脚本删除ios中未使用的图片(纸书上有点小问题,参考github上的issue:使用脚本删除i ...
- PandoraBox 支持3G无线上网卡(联通卡3G卡)(一)
一:笔者采用的是系统是OpenWrt之PandoraBox,内核版本3.3.8:硬件设备是MTK的7620开发板. 其中怎么搭建openwrt开发环境在此不用多说,因为既然想实现3G无线上网卡拨号上网 ...
- JavaScript中label语句的使用
之前在读<javascript高级程序设计>的时候,看到过lable语句,当时看完感觉好像很少用到,但是今天,刚好在项目终于到了合适的场景,合理使用label可以大幅度优化性能. 首先来简 ...
- (org.openqa.selenium.WebDriverException: Unable to launch the app: Error: Trying to start logcat capture but it's already started! )错误解决办法
新增: capabilities.setCapability("autoLaunch",false); 将setup中的: driver = new AndroidDriver(n ...
- sanic官方文档解析之Exception和Middleware,Listeners
1,异常 异常是从处理请求内部抛出来的,并且通过Sanic自动的被处理异常,,异常用第一个参数携带异常信息,还可以接受在HTTP响应中要传递回的状态代码.引发异常 1.1引发异常 自动触发异常,,简单 ...
- HDU 6068 Classic Quotation KMP+DP
Classic Quotation Problem Description When online chatting, we can save what somebody said to form h ...
- 安装NLTK
在网上找了一圈,没找到几个靠谱的安装流程,在http://nltk.org/install.html上找到各平台下安装流程: Windows平台: 以下操作假定你的机器上还没有安装Python,如果你 ...
- Joomla中的Task 和view 深入学习
[本文转自:梦溪笔记] Joomla 是一个优秀的CMS系统,她可以让你快速的完成一个网站的建设,她提供组件,模块,模板能够满足你大部分的网站需求.而组件在其中举足轻重. 一.基本知识 组件(comp ...