久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

采用整數(shù)并返回所有可能的加法格式的算法

Algorithm that takes an integer and returns all possible format of addition(采用整數(shù)并返回所有可能的加法格式的算法)
本文介紹了采用整數(shù)并返回所有可能的加法格式的算法的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我需要編寫一個(gè)算法,它接受一個(gè)整數(shù)并返回所有可能的加法格式

I need to write an algorithm that takes an integer and returns all possible format of addition

例如

如果我進(jìn)入:6

它將返回以下字符串:

 0+6=6
 1+1+1+1+1+1=6
 1+1+1+1+2=6
 1+1+1+3=6
 1+1+4=6
 1+5=6
 2+1+1+1+1=6
 2+1+1+2=6
 2+1+3=6
 2+4=6
 3+1+1+1=6
 3+1+2=6
 3+3=6
 4+1+1=6
 4+2=6
 5+1=6
 6+0=6

這是我的嘗試:

import java.util.*;
public class Test
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter an integer? ");
        int num = in.nextInt();
        System.out.println();
        calculate(num);
    }
    private static void calculate(int n)
    {
        int[] arInt = new int[n];
        for(int i = 0; i <= n; i++)
        {
            for(int j = 0; j <= n; j++)
            {
                arInt[j] = i;
            }
            // ...
        }
    }
}

推薦答案

我同意 Brad.完成此操作的最佳方法可能是通過遞歸.事實(shí)上,我昨晚正在研究與此相關(guān)的事情.我使用遞歸回溯算法解決了我的問題.查看維基百科頁面:回溯

I agree with Brad. The best way to complete this would probably be through recursion. In fact, I was working on something related to this last night. I solved my problem using a recursive backtracking algorithm. Check out the Wikipedia page: Backtracking

現(xiàn)在,我不保證沒有更好、更簡(jiǎn)單的方法來解決這個(gè)問題.但是,通過遞歸回溯,您將找到所有解決方案.

Now, I make no guarantees that there aren't better, less complex ways to solve this. However, with recursive backtracking you will find all the solutions.

但有一點(diǎn)需要注意,即 0.您可以將任意數(shù)量的零放入加法/減法中,結(jié)果會(huì)相同.

One thing to watch out for though, that 0. You can throw any amount of zeros into an addition/subtraction and it will come out the same.

這篇關(guān)于采用整數(shù)并返回所有可能的加法格式的算法的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環(huán)繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動(dòng)生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數(shù)據(jù)庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對(duì)象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: www.久久久久久久久久久久 | 欧美视频一区二区三区 | 中文天堂在线观看 | 二区高清 | 亚洲97 | 久久国| 一区二区三区在线播放 | 一区二区三区国产在线观看 | 在线观看黄色电影 | 国产91在线 | 欧美 | 成人在线观看网站 | 亚洲精品在线国产 | 国产精品久久久av | 国产婷婷色综合av蜜臀av | 欧美激情在线精品一区二区三区 | 久久久久无码国产精品一区 | 国产精品区二区三区日本 | 久久精品久久久久久 | 中国大陆高清aⅴ毛片 | 国产精品福利久久久 | av一级在线观看 | 亚洲精品二区 | 欧美一区二区三区久久精品 | 91精品国产乱码久久久 | 秋霞在线一区 | 孰女乱色一区二区三区 | 国产成人福利在线观看 | 成人久久| 午夜伦理影院 | 久久精品二区 | 国产91久久精品一区二区 | 日韩免费一区二区 | www.47久久青青 | 国产99在线 | 欧美 | caoporon| 日批av | 亚洲电影第三页 | 国产伦精品一区二区三区精品视频 | 精品在线免费观看视频 | 美女黄18岁以下禁止观看 | 国产主播第一页 |