POJ 3187 Backward Digit Sums(dfs)

ISP 基础知识储备 ISP(image signal processing),图像信号处理芯片,在手机摄像头和车载摄像头等领域有着广泛应用,是图像信号处理的核心芯片。 ISP pipeline 流程图如下: 光线经过lens镜头,投射到sensor上,经过光电转换成模拟电信号,再由A/D转换成数字信号,交给ISP芯片进行一系列的处理,在LENS部分也需要进行镜头校正、颜色矫正等一些操作。 然后,得到的bayer ... 阅读详情

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;
}






倾斜摄影数据转换为3DTile格式的方法:基于CesiumLab GIS 通过使用CesiumLab GIS,倾斜摄影数据可以方便地转换为3DTile格式,并在CesiumJS等3D地理信息可视化工具中进行展示和分析。一旦成功导入3DTile数据,就可以在CesiumLab GIS中利用其强大的可视化和分析功能进行进一步的处理。转换完成后,可以将生成的3DTile数据导入到CesiumLab GIS中进行可视化和分析。启动CesiumLab GIS应用程序,并按照界面上的指导导入转换后的3DTile数据。脚本将开始执行,并将倾斜摄影数据转换为3DTile格式。 阅读详情

相关推荐

Pspice安装教程:Windows系统完整指南(含环境变量设置)

详细讲解在Windows系统中完成Pspice安装的全过程,涵盖安装步骤与关键的环境变量设置,帮助用户顺利运行仿真工具。适合初学者快速上手pspice安装教程中的核心环节。

weixin_42230607的博客 1176

Backward Digit Sums

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

u013546334的专栏 481

STM32F407+HAL库+W5500实现TCP通讯 个人项目总结

推荐阅读此博客 cv即可成功首先需要一个可以进行串口调试的工程,方便进行调试。1.在W5500官网移植库文件重点是Ethernet这个文件夹将里面的 socket.c,socket.h,wizchip_conf.c,wizchip_conf.h,还有根据W5500文件夹里的w5500.c和w5500.h移植到自己的工程里面。然后再创建一个.c和.h文件 我的叫w5500_port_hal.c 和w5500_port_hal.h 记得将.h文件链接到工程里。

a234abr的博客 2247

Backward Digit Sums--POJ3187

《挑战程序设计第二版》

小菜鸟博客 271

USB3.0 Type-B连接器SSTX/SSRX信号定义常见错误与硬件设计避坑指南

本文详细解析了USB3.0 Type-B连接器中SSTX/SSRX信号的定义标准与常见设计错误。针对连接器厂商图纸可能出现的信号标识错误,提供了实用的排查方法和硬件设计避坑指南,帮助工程师避免因引脚定义颠倒导致的通信降级或故障,确保USB3.0高速传输的稳定性。

gg901的博客 1265

在MCUXpresso上通过J-link烧写KW45

背景: KW45B是nxp 的ble npi产品,其使用的IDE为MCUXpressso或者IAR,MCUXpressso有一些bug,但是由于MCUXpressso阅读查找代码相对IAR容易,所以我经常使用的MCUXpressso进行开发。当然IAR也有其优势,比如编译、烧写速度相对MCUXpressso更快,是比较通用的一个平台,而MCUXpressso是NXP独有的。 Kw45有两种烧写方式,一是使用MCUlink,二是使用Jlink。NXP ble 产品线提供的IDE资料里有最新的15.0版本的

weixin_41889258的博客 2859

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

(dfs+思维杨辉三角)

m0_74969835的博客 475

【故障处理】- ORA-01722

在执行升级脚本@?/rdbms/admin/catupgrd.sql时报错ora-01722。

weixin_39099660的博客 854

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

11、基于多阵列电极的表面肌电信号运动估计

本文介绍了一种基于多阵列电极的表面肌电信号运动估计技术,旨在实现对手腕和手指运动的高精度估计,解决传统人机接口在操控多自由度机器人时的局限性。通过多阵列电极系统采集前臂肌肉活动信号,结合独立成分分析(ICA)和非负矩阵分解(NMF)等信号处理方法,提取肌肉协同作用,进而生成运动指令以控制机器人或假肢手。文章对比了多阵列电极与传统电极的优势,展示了运动估计算法的整体流程,并以假肢手控制为例说明其实际应用。最后探讨了该技术在测量精度、应用拓展、智能化和便携化等方面的未来发展方向。该技术为假肢控制、康复训练和人机

ik678901234的博客 87

手把手教你学Simulink--基于新能源并网与协调控制的场景实例:双馈异步风力发电机并网运行仿真

随着“双碳”目标的推进,风力发电已成为新能源并网的核心组成部分。其中,双馈异步风力发电机(Doubly-Fed Induction Generator, DFIG)因其变频器容量小(仅处理转差功率)、可实现有功/无功独立调节、运行效率高等优势,广泛应用于现代兆瓦级风电机组。DFIG系统通过转子侧变流器(Rotor-Side Converter, RSC)和网侧变流器(Grid-Side Converter, GSC)实现对发电机转矩与电网无功的精确控制,支持最大功率点跟踪(MPPT)和。

MHD0815的博客 280

poj3187Backward Digit Sums(DFS)

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

大洋深处 1044

Python爬虫实战:58同城租房信息分析与可视化,寻找高性价比房源

随着城市化进程加快,租房需求日益增长。58同城作为国内领先的本地生活服务平台,汇聚了大量房源信息。本教程将使用最新的Python爬虫技术获取58同城租房数据,通过数据分析与可视化揭示各区域租金水平,并运用机器学习算法找出性价比高的房源。本项目将使用异步爬虫、反爬对抗技术、数据清洗、可视化分析和机器学习建模等技术栈。

2201_76125261的博客 1279

[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

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

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

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

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

VC中sqlite的使用

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

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、付费专栏及课程。

余额充值