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

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

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

問題描述

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

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

例如

如果我進入: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.完成此操作的最佳方法可能是通過遞歸.事實上,我昨晚正在研究與此相關的事情.我使用遞歸回溯算法解決了我的問題.查看維基百科頁面:回溯

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

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

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.

但有一點需要注意,即 0.您可以將任意數量的零放入加法/減法中,結果會相同.

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.

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

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

相關文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數據庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 久草新在线 | 国产精品福利在线观看 | 在线视频一区二区三区 | 青青草综合 | 人人干超碰 | 日韩中文字幕在线观看 | 午夜在线精品 | 国产精品99久久久久久动医院 | 人人射人人插 | 精品国产乱码久久久 | 日韩伦理一区二区 | 成人午夜视频在线观看 | 国产精品污污视频 | 99riav国产一区二区三区 | 91精品国产一区二区三区 | 永久看片 | 日韩欧美视频 | 国产成人在线视频播放 | 日韩精品视频在线 | 国产亚洲精品精品国产亚洲综合 | 一区二区三区在线免费观看 | 精品视频一区二区三区在线观看 | 亚洲精品白浆高清久久久久久 | 亚洲一区二区三区免费观看 | 国产精品资源在线观看 | 久久亚洲欧美日韩精品专区 | 欧美一级黑人aaaaaaa做受 | 国产91综合一区在线观看 | 粉嫩av | 91精品国产欧美一区二区 | 一区二区视频在线 | 2019天天干天天操 | 亚洲一区二区在线电影 | 日本久久一区二区三区 | 国产在线观 | 亚洲成在线观看 | 午夜三级视频 | 欧美日韩久久久 | 欧美在线观看一区 | 毛片一区二区三区 | 毛片一区二区 |