hdu--1258--Sum It Up(Map水过)
Sum It Up
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6581 Accepted Submission(s): 3451
/*
Name: hdu--1258--Sum It Up
Copyright: ©2017 日天大帝
Author: 日天大帝
Date: 29/04/17 18:48
Description: dfs,C++map水过
*/
#include<iostream>
#include<cstring>
#include<map>
using namespace std;
void dfs(int,int,map<int,int,greater<int>>::iterator it);
;
int res[MAX];
int n,t,flag;
map<int,int,greater<int>> mymap;
int main(){
ios::sync_with_stdio(false);
while(cin>>n>>t,n||t){
mymap.clear();
flag = ;
memset(res,,sizeof(res));
; i<t; ++i){
int a;cin>>a;
mymap[a]++;
}
cout<<"Sums of "<<n<<":"<<endl;
dfs(,,mymap.begin());
)cout<<"NONE"<<endl;
}
;
}
void dfs(int sum,int ct,map<int,int,greater<int>>::iterator iter){
if(sum == n){
flag = ;
cout<<res[];
; i<ct; ++i){
cout<<"+"<<res[i];
}
cout<<endl;
}
for(auto it=iter; it!=mymap.end(); ++it){
)continue;
; i--){
if(sum+(i*it->first) > n)continue;
; k<i; ++k){
res[ct + k] = it->first;
}
auto ipoint = it;
dfs(sum+(i*it->first),ct+i,++ipoint);
}
}
}
hdu--1258--Sum It Up(Map水过)的更多相关文章
- HDOJ(HDU).1258 Sum It Up (DFS)
HDOJ(HDU).1258 Sum It Up (DFS) [从零开始DFS(6)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双 ...
- 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 1258 Sum It Up(dfs+去重)
题目大意: 给你一个总和(total)和一列(list)整数,共n个整数,要求用这些整数相加,使相加的结果等于total,找出所有不相同的拼凑方法. 例如,total = 4,n = 6,list = ...
- HDU 1258 Sum It Up(DFS)
题目链接 Problem Description Given a specified total t and a list of n integers, find all distinct sums ...
- HDU 1258 Sum It Up
Sum It Up Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total S ...
- (step4.3.4)hdu 1258(Sum It Up——DFS)
题目大意:输入t,n,接下来有n个数组成的一个序列.输出总和为t的子序列 解题思路:DFS 代码如下(有详细的注释): #include <iostream> #include <a ...
- HDU 4432 Sum of divisors (水题,进制转换)
题意:给定 n,m,把 n 的所有因数转 m 进制,再把各都平方,求和. 析:按它的要求做就好,注意的是,是因数,不可能有重复的...比如4的因数只有一个2,还有就是输出10进制以上的,要用AB.. ...
- HDU 1258 Sum It Up (DFS)
Sum It Up Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total S ...
- HDOJ/HDU 1251 统计难题(字典树啥的~Map水过)
Problem Description Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己 ...
随机推荐
- eclispe JavaEE 配置tomcat
http://blog.csdn.net/hongshan50/article/details/8293526 http://blog.csdn.net/longshengguoji/article/ ...
- PHP中小小的header函数
不废话,直接说功能 1.重定向,语法: header("location:http://www.lemon-x.ga"); file_put_contents("./te ...
- Kafka 源代码分析之log框架介绍
这里主要介绍log管理,读写相关的类的调用关系的介绍. 在围绕log的实际处理上.有很多层的封装和调用.这里主要介绍一下调用结构和顺序. 首先从LogManager开始. 调用关系简单如下:LogMa ...
- Java添加JDBC
添加JDBC 1.SQL Server SQL Server2005 下载 sqljdbc_4.0 https://www.microsoft.com/en-us/download/details.a ...
- Visual Studio自动添加头部注释 -C#开发2010-2013验证
在团队开发中,头部注释是必不可少的.但在开发每次新建一个类都要复制一个注释模块也很不爽,所以得想个办法让开发工具自动生成我们所需要的模板.....操作方法如下: 找你的vs安装目录, 比如我的是在D盘 ...
- HTML中使用JavaScript的三种方式及优缺点
1.内部js: 在直接在页面的<script></script>标签内写js代码 优点:相对于使用行内js,内部js代码较为集中,与页面结构的实现代码耦合度较低,比较便于维 ...
- linux中日志介绍
linux日志 linux日志大多是以明文存储,一般存储在/var/log目录中,linux系统中主要有三个日志子系统:连接时间日志,进程统计日志,错误日志. 连接时间日志 连接时间日志是有多个程序执 ...
- 50行代码实现的高性能动画定时器 raf-interval
写在前面 raf-interval 是基于 window.requestAnimationFrame() 封装的定时器. Github: https://github.com/dntzhang/raf ...
- Domains域
一个域是一个criteria(度量标准)列表,每个criterion(标准尺度)是一个三元列表或者元组:field_name,operator,value. field_name(str) 当前模型的 ...
- 常用的DNS
中国互联网络中心(推荐,安全又快速):1.2.4.8.210.2.4.8.101.226.4.6(电信及移动).123.125.81.6(联通)阿里DNS:223.5.5.5.223.6.6.6goo ...