POJ 3187 Backward Digit Sums(dfs)

随机化策略——随机变量rand、约束constraint、权重dist、随机数产生示例 文章目录一、随机变量类型1.1.rand随机变量1.2.randc随机变量二、随机化约束2.1.constraint指定约束范围2.1.1.关系操作符约束(>、<、=、>=、<=)2.1.2.范围操作符约束(inside)2.1.3.权重分布约束(dist)2.1.4.条件约束(if-else; ->)三、启动随机化——randomize( )函数四、关闭或打开随机变... 阅读详情

Backward Digit Sums
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 4281 Accepted: 2470

Description

FJ and his cows enjoy playing a mental game. They write down the numbers from 1 to N (1 <= N <= 10) in a certain order and then sum adjacent numbers to produce a new list with one fewer number. They repeat this until only a single number is left. For example, one instance of the game (when N=4) might go like this: 

    3   1   2   4

      4   3   6

        7   9

         16
Behind FJ's back, the cows have started playing a more difficult game, in which they try to determine the starting sequence from only the final total and the number N. Unfortunately, the game is a bit above FJ's mental arithmetic capabilities. 

Write a program to help FJ play the game and keep up with the cows.

Input

Line 1: Two space-separated integers: N and the final sum.

Output

Line 1: An ordering of the integers 1..N that leads to the given sum. If there are multiple solutions, choose the one that is lexicographically least, i.e., that puts smaller numbers first.

Sample Input

4 16

Sample Output

3 1 2 4

Hint

Explanation of the sample: 

There are other possible sequences, such as 3 2 1 4, but 3 1 2 4 is the lexicographically smallest.

Source




这个题意就是给你一个n和m,然后n个数排列后像上面的那样计算出一个数,如果和m想同就ok,输出最小的序列


思路:

  直接dfs枚举每个序列,如果有满足结束,不过我代码中有个传地址的地方让我bug了几分钟,细节在代码中



#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 20

int a[N],ans[N];
int vis[N];
int n,m;
int yes;


int fdd(int a[],int n)
{
    if(n==1)  return a[0];

    int i;
    for(i=0;i<n-1;i++)
        a[i]=a[i]+a[i+1];

    return fdd(a,n-1);
}

void dfs(int pos)
{
    int i;
    if(yes)  return ;

    if(pos==n)
    {
        for(i=0;i<n;i++) //这里必须把ans转移到a数组中,
                         //因为下面是地址传递会改变数组的值
            a[i]=ans[i];

            if(fdd(a,n)==m)
            {
              for(i=0;i<n;i++)
                if(i==0)
                  printf("%d",ans[i]);
                 else
                  printf(" %d",ans[i]);

                yes=1;
            }
        return ;
    }

    for(i=1;i<=n;i++)
        if(!vis[i])
    {
        vis[i]=1;
        ans[pos]=i;
        dfs(pos+1);
        vis[i]=0;
    }

}

int main()
{
    int i,j;
    while(~scanf("%d%d",&n,&m))
    {
         yes=0;
        memset(vis,0,sizeof(vis));
        for(i=1;i<=n;i++)
        {
            vis[i]=1;
            ans[0]=i;
            dfs(1);
            vis[i]=0;
        }
    }

    return 0;
}






【过检测】2026调试级去虚拟化虚拟机成品 EternalBlaze调试级虚拟机是由恒烈开发的定制化VMware环境,适用于逆向工程、病毒分析等专业场景。该虚拟机基于Windows 10 1909专业版,预装Python/JDK等开发环境和逆向工具包,支持快照回溯功能。特色包括:一键去虚拟化方案、双机调试支持、驱动开发环境等。适用场景涵盖CTF竞赛、软件调试、病毒行为分析等,但不支持DX12游戏和视频盗录。使用前需按步骤关闭安全中心、安装特定VMware版本并执行去虚拟化操作。虚拟机提供基础版和逆向调试增强版两种配置,均预装必要工具链。(149字) 阅读详情

相关推荐

3D医学影像分割新突破:手把手教你用MedSAM2快速标注CT/MRI数据(附3D Slicer插件配置)

本文详细介绍了如何利用MedSAM2模型进行3D医学影像分割,包括从环境准备到3D Slicer插件配置的全流程。通过实战案例和技巧分享,帮助医疗从业者快速掌握CT/MRI数据的高效标注方法,提升医学影像分析的准确性和效率。

ujm5678901的博客 299

Backward Digit Sums

题意大概是:知道数的个数n和数通过题意的方法

u013546334的专栏 481

05-SA8155 QNX Display框架及代码分析(1)

显示是非常重要的一个模块,人机交互的桥梁。那么SA8155 Hypervisor显示是如何处理的呢。对处理流程非常的好奇O(∩_∩)O哈哈~。TODO。

静虚待令,有物混成 1万+

Backward Digit Sums--POJ3187

《挑战程序设计第二版》

小菜鸟博客 271

3D打印切片软件Cura及CuraEngine原理分析

引言         年初开始进入3D打印行业,受命以Cura为基础,研发一款自主的3D打印切片软件。         自主研发要取其长处,补其不足,首先自然是要搞清楚Cura到底做了什么,读Cura的代码是必需的。我一向都觉得比起自己写代码来,读别人的代码是一个漫又而痛苦的过程,读者的思想与写者总有偏差,往往又无法验证自己的猜想是否正确,只叹人脑不是电脑,无法把眼前的代码从头到尾执行一遍...

AiDiShengDeXiaoWu的博客 4420

CCS8.1 导入CCS3.3工程方法

    CCS3.3作为开发人员使用最广开发工具,研究人员手上存在不少该版本的建立的程序版本,然而随着TI公司推出高级版本的CCS平台,在新的平台上集成了更加丰富的功能和优点。利用新版本的平台在开发和编译旧版本工程上可以节省大量时间和精力。在使用新版本开发3.3版本工程时,首要解决的就是加载3.3的工程文件,现将加载过程记录如下: 第一步:Project-&gt;Import Legacy CC...

1万+

P1118 [USACO06FEB] Backward Digit Sums G/S(dfs+思维杨辉三角)

(dfs+思维杨辉三角)

m0_74969835的博客 475

智能化运维(AIOps)

• 调查显示,54.79%的企业当前着重关注智能运维的质量领域(包括异常检测、告警收敛、根因分析、 故障处置等)能力建设,其次45.77%的企业关注效率领域,45.49%的企业关注成本领域,30.82%的 企业关注安全领域。从目前的发展情况来看,现阶段AIOps能力大多集中在L2级别, 主要以系统辅助分析,帮助人工进行决策和操作为主,较为领先的 能力实践可以达到L3级别,而L4和L5级别随着AIOps的技术发展 和能力的逐步增强,将是未来智能运维能力建设的发展方向和目标。

追求更专业的设计 3097

POJ3187——Backward Digit Sums(暴力)

题目链接         这题没什么特别要注意的,直接next_permutation(),暴力走起。 #include #include #include #include #include using namespace std; int a[15]={0}; int b[15]={0}; int main() { //freopen("in.in","r",st

Jason_crawford的博客 402

Vivado实战:AXI转PCIe IP核配置全流程(含性能优化技巧)

本文详细介绍了在Vivado环境中配置AXI转PCIe IP核的全流程,包括工程准备、IP核参数设置、BAR空间配置、中断系统优化以及TLP传输效率提升等关键步骤。特别分享了经过验证的性能优化技巧,帮助开发者显著提升PCIe链路的吞吐量和稳定性,适用于视频采集、高速数据记录等应用场景。

weixin_30892037的博客 552

Cortex-M TrustZone实战:从硬件隔离到安全交互的嵌入式开发指南

在嵌入式系统开发中,硬件安全隔离是构建可信执行环境(TEE)的核心技术。其原理是通过处理器硬件机制,将系统资源划分为安全与非安全域,实现内存、外设和代码的强制访问控制。这项技术的核心价值在于,它能在单一芯片上为资源受限的物联网(IoT)设备、智能传感器等提供芯片级的安全基础,无需依赖外置安全元件,从而降低BOM成本并简化设计。典型的应用场景包括保护设备密钥、实现安全启动、构建安全服务(如加密、密钥管理)以供应用程序调用。本文聚焦于Arm Cortex-M系列微控制器上的TrustZone技术实现,针对开发中

weixin_42639246的博客 300

poj3187Backward Digit Sums(DFS)

题目链接: huangjing 思路: 这个题目想到dfs很容易,但是纠结在这么像杨辉三角一样计算那些值,这个我看的队友的,简直厉害,用递归计算出杨辉三角顶端的值。。。。具体实现详见代码。。。 题目: Language: Default Backward Digit Sums Time Limit: 1000MS   Memo

大洋深处 1044

YOLOv11改进 - C3k2融合 | C3k2 融合 ARConv 自适应矩形卷积:动态调整卷积核形状与采样点

本文介绍了将自适应矩形卷积(ARConv)模块与YOLOv11相结合的方法。ARConv是针对遥感图像全色锐化任务设计的创新卷积模块,可自适应调整卷积核形状与采样点数量,解决传统卷积刚性限制,实现高效特征提取。其工作流程包括学习卷积核高度和宽度、选择采样点数量、生成采样图、卷积实现与空间自适应增强。我们将集成ARConv的C3k2_ARConv模块引入YOLOv11,对相关代码进行修改和注册,并配置了yolov11 - C3k2_ARConv.yaml文件。实验脚本显示,该结合方式应用于目标检测任务。

魔改工程师的博客 1005

[poj]3187 Backward Digit Sums [dfs]

FJ and his cows enjoy playing a mental game. They write down the numbers from 1 to N (1 <= N <= 10) in a certain order and then sum adjacent numbers to produce a new list with one fewer number. They re

chutzpah 318

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

Backward Digit Sums - POJ 3187 DFS

Backward Digit Sums Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4860   Accepted: 2808 Description FJ and his cows enjoy playing a mental game. They write

BlueFissure's Blog 475

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

POJ 3187- Backward Digit Sums(DFS+全排列)

E - Backward Digit Sums Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 3187 Appoint description:  System Crawler  (2016-05-02)

梧桐下的四叶草 564

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

POJ 3187 Backward Digit Sums(DFS)

Description FJ and his cows enjoy playing a mental game. They write down the numbers from 1 to N (1 <= N <= 10) in a certain order and then sum adjacent numbers to produce a new list with one fewer

Ailing 272

POJ3187Backward Digit Sums【dfs 暴搜水题】

Language: Default Backward Digit Sums Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5157   Accepted: 2984 Description FJ and his cows enjoy playing a

走一步再走一步 850

POJ 3187 Backward Digit Sums (DFS 全排列)

Backward Digit Sums Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4531   Accepted: 2604 Description FJ and his cows enjoy playing a mental game. They write

EaShion1994的专栏 705

poj3187Backward Digit Sums(暴力dfs)

题目请戳这里 题目大意:给一个n( 题目分析:最坏10!复杂度,直接爆搜啦,剪枝都免了,妥妥的 详情请见代码: #include #include #include #include using namespace std; const int N = 11; int lcm[N][N]; bool flag[N],ok; int n,sum; void dfs(int cur,in

ophunter的专栏 1386

POJ 3187 Backward Digit Sums (dfs全排列)

Backward Digit Sums Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4705   Accepted: 2703 Description FJ and his cows enjoy playing a mental game. They wri

TaoSama's Microcosm 496

poj 3187 Backward Digit Sums(穷竭搜索dfs)

Description FJ and his cows enjoy playing a mental game. They write down the numbers from 1 to N (1 <= N <= 10) in a certain order and then sum adjacent numbers to produce a ne...

dielucuan8830的博客 125

POJ NO.3187 Backward Digit Sums(DFS)

问题描述:给出n,sum。类似于杨辉三角,让你求出最顶尖为sum的第n层所有元素。 注意:答案有多种的按照字典序较小的那个输出。 题目链接:点击打开链接 代码: #include #include #include #include #include #include #define INF 0x3f3f3f3f #define MAX 30000 using namespace std

363

【POJ 3187 Backward Digit Sums】 + DFS + 排列组合

Backward Digit Sums Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7041 Accepted: 4083 DescriptionFJ and his cows enjoy playing a mental game. They write down the numbers from 1 to N (

楚江枫 451

poj 3187 Backward Digit Sums(dfs暴搜)

问题描述 FJ and his cows enjoy playing a mental game. They write down the numbers from 1 to N (1 <= N <= 10) in a certain order and then sum adjacent numbers to produce a new list with one fewer number

坏坏的薯片 287

POJ-3187(Backward Digit Sums)(全排列+dfs())

POJ-3187(Backward Digit Sums)(全排列+dfs()) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5706   Accepted: 3309 Description FJ and his cows enjoy playing a me

hpulw 758
上一篇: POJ 2472 106 miles to Chicago
下一篇: POJ 3370 Halloween treats(抽屉原理)
左眼皮跳跳~
博客等级 码龄13年 17粉丝 400原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值