第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

用java程序?qū)崿F(xiàn)一道排列組合的數(shù)學題?

用java程序?qū)崿F(xiàn)一道排列組合的數(shù)學題?

尚方寶劍之說 2018-10-16 21:13:02
0-9選6個數(shù)加起來等于33的排列組合,數(shù)字可以重復。
查看完整描述

2 回答

?
慕萊塢森

TA貢獻1810條經(jīng)驗 獲得超4個贊

簡單粗暴的排列算法:

public class BruteForceArrangement {

  public static void main(String[] args) {

    for (int a = 0; a < 10; a++)

      for (int b = 0; b < 10; b++)

        for (int c = 0; c < 10; c++)

          for (int d = 0; d < 10; d++)

            for (int e = 0; e < 10; e++)

              for (int f = 0; f < 10; f++)

                if (a + b + c + d + e + f == 33)

                  System.out.printf("%d%d%d%d%d%d\n", a, b, c, d, e, f);

  }

}

簡單粗暴的組合算法:

public class BruteForceCombination {

  public static void main(String[] args) {

    for (int a = 0; a < 10; a++)

      for (int b = a; b < 10; b++)

        for (int c = b; c < 10; c++)

          for (int d = c; d < 10; d++)

            for (int e = d; e < 10; e++)

              for (int f = e; f < 10; f++)

                if (a + b + c + d + e + f == 33)

                  System.out.printf("%d%d%d%d%d%d\n", a, b, c, d, e, f);

  }

}


查看完整回答
反對 回復 2018-10-21
  • 2 回答
  • 0 關(guān)注
  • 905 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號