ACM-Special Array
题目描述:Special array
输入
输入只有一行,包含每个数列的元素个数n和数列元素的和m。
输出
按照字典逆序输出所有的数列,每个数列输出一行,每个数列元素用一个空格分开。
样例输入
4 8
样例输出
5 1 1 1
4 2 1 1
3 3 1 1
3 2 2 1
2 2 2 2 解题思路:很简单的一道DFS题目,减枝策略可以除了常规的策略之外,再加上当前搜索数目最大不超过剩余数-剩余位置个数。
// specical array.cpp : 定义控制台应用程序的入口点。
// #include "stdafx.h" #include <iostream>
#include <cstring>
using namespace std;
const int MAX = ;
int n, m, arr[MAX]; //最后一个数,已经填数的个数,数组总和
void DFS(int cur, int cnt, int sum)
{
if (cnt == n)
{
if (sum == m)
{
for (int i = ; i < n; i++)
{
if (i != n - ) cout << arr[i] << " ";
else cout << arr[i] << endl; }
}
return; }
for (int i = cur; i >= ; i--) // 从大到小开始搜索
{
if (i + sum + n - cnt - <= m) //n-cnt-1 是剩余大小
{
arr[cnt] = i;
DFS(i, cnt + , sum + i);
} }
} int main()
{
while (cin >> n >> m)
{
memset(arr, , sizeof(arr)); for (int i = m - n + ; i >= ; i--)
{
arr[] = i;
DFS(i, , i);
}
} return ;
}
ACM-Special Array的更多相关文章
- ACM会议列表与介绍(2014/05/06)
Conferences ACM SEACM Southeast Regional Conference ACM Southeast Regional Conference the oldest, co ...
- 观V8源码中的array.js,解析 Array.prototype.slice为什么能将类数组对象转为真正的数组?
在官方的解释中,如[mdn] The slice() method returns a shallow copy of a portion of an array into a new array o ...
- CF959D Mahmoud and Ehab and another array construction task 数学
Mahmoud has an array a consisting of n integers. He asked Ehab to find another array b of the same l ...
- codeforces-473D Mahmoud and Ehab and another array construction task (素数筛法+贪心)
题目传送门 题目大意:先提供一个数组,让你造一个数组,这个数组的要求是 1 各元素之间都互质 2 字典序大于等于原数组 3 每一个元素都大于2 思路: 1.两个数互质的意思就是没有公因子.所以每 ...
- Codeforces 959 D Mahmoud and Ehab and another array construction task
Discription Mahmoud has an array a consisting of n integers. He asked Ehab to find another arrayb of ...
- 信息检索盛会 微软“领衔主演”——记ACM SIGIR 2013信息检索国际会议
微软"领衔主演"--记ACM SIGIR 2013信息检索国际会议" title="信息检索盛会 微软"领衔主演"--记ACM SIGIR ...
- SCI&EI 英文PAPER投稿经验【转】
英文投稿的一点经验[转载] From: http://chl033.woku.com/article/2893317.html 1. 首先一定要注意杂志的发表范围, 超出范围的千万别投,要不就是浪费时 ...
- sdn测量论文简介
Prelude: Ensuring Inter-Domain Loop-Freedom in SDN-Enabled Networks 来源:APNet: The Asia-Pacific Works ...
- CIKM Competition数据挖掘竞赛夺冠算法陈运文
CIKM Competition数据挖掘竞赛夺冠算法陈运文 背景 CIKM Cup(或者称为CIKM Competition)是ACM CIKM举办的国际数据挖掘竞赛的名称.CIKM全称是Intern ...
随机推荐
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 按钮:禁用按钮
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 将varchar2类型字段改成clob类型
--增加临时新字段alter table base_temp add temp clob; --将需要改成大字段的项内容copy到大字段中update base_temp set temp=con ...
- Oracle笔记--Sql语句
1.SQL的三种类型语句: --1)DML(Data Manipulation Language)数据操纵语言 --2)DDL(Data Definition Language):数据定义语言 --3 ...
- mac java 装机清单
1. JDK8 2. Eclipse IDE for Enterprise Java Developers 3. maven 4. Postman 5. VS Code 6. finalshell ( ...
- 吴裕雄--天生自然Hadoop学习笔记:Hadoop简介
Hadoop是一个由Apache基金会所开发的分布式系统基础架构.用户可以在不了解分布式底层细节的情况下,开发分布式程序.充分利用集群的威力进行高速运算和存储.Hadoop实现了一个分布式文件系统(H ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 按钮:按钮组
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- greenplum 存储过程 返回结果集多列和单列
参考: http://francs3.blog.163.com/blog/static/4057672720125231223786/
- jsp el表达式判空
https://www.cnblogs.com/sxdcgaq8080/p/8119186.html
- 部署 Helm【转】
本节我们将安装和部署 Helm 客户端和 Tiller 服务器. Helm 客户端 通常,我们将 Helm 客户端安装在能够执行 kubectl 命令的节点上,只需要下面一条命令: curl http ...
- 新闻网大数据实时分析可视化系统项目——19、Spark Streaming实时数据分析
1.Spark Streaming功能介绍 1)定义 Spark Streaming is an extension of the core Spark API that enables scalab ...