久久久久久久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(使用線程逐塊處理文件)
主站蜘蛛池模板: 亚洲国产黄色av | 成年人在线播放 | 毛片综合 | 日韩欧美一区二区三区免费观看 | 久久精品国产99国产 | 99久久免费精品国产男女高不卡 | 在线国产小视频 | 中文字幕在线观看www | 国产精品18hdxxxⅹ在线 | 一级黄色片免费 | 国产精品精品久久久 | 欧美一区二区三区在线视频 | 在线看片国产精品 | 欧美日韩在线观看视频网站 | 精品在线看 | 成人二区 | 91欧美激情一区二区三区成人 | 日韩高清一区二区 | 久久精品国产亚洲一区二区 | 国产精品观看 | 国产免费va | 欧美国产激情二区三区 | 亚洲精品无 | 天天操网 | 欧美综合一区二区 | 男人天堂网址 | 亚洲人成在线播放 | 国产精品久久久久久久久久久久久 | 欧美精品乱码久久久久久按摩 | 亚洲欧美中文日韩在线 | 色综合久久天天综合网 | 国产一区二区三区免费 | 高清成人av | 在线亚洲免费视频 | 日韩av一区二区在线观看 | 成人国产精品色哟哟 | 不卡一区二区三区四区 | 在线观看免费av片 | 99色综合 | 国产三级一区二区 | 中文无码日韩欧 |