十槍90環--遞歸

          題目:打十槍,一共打中90環,可以打成0環。共有多少種打法?

          public static void main(String[] args) {
          ????cumput(90, 9);
          ???? System.out.println("總數:"+sum);
          ?}?

          static int sum;
          ?static int store[] = new int[10];
          ?static void output()
          ?{
          ???? for(int i = 9; i>=0; --i)
          ???? {
          ??????? System.out.print(store[i] + " ");
          ???? }
          ??? System.out.println();
          ??? ++sum;
          ?}

          ?
          ?static void cumput(int score, int num)
          ?{
          ??? // 無法完成的事件
          ??if(score < 0 || score > (num+1)*10 ) //次數num為0~9
          ?????? return;
          ???
          ??? if(num == 0)
          ??? {
          ???????? store[num] = score;
          ???????? output();
          ???????? return;
          ??? }
          ???
          ??? for(int i = 0; i <= 10; ++i)
          ??? {
          ???????? store[num] = i;
          ???????? cumput(score - i, num - 1);
          ??? }
          ?}

          posted on 2010-01-19 14:29 飛熊 閱讀(380) 評論(0)  編輯  收藏 所屬分類: 算法

          <2010年1月>
          272829303112
          3456789
          10111213141516
          17181920212223
          24252627282930
          31123456

          導航

          統計

          常用鏈接

          留言簿(1)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          收藏夾

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 洛阳市| 华宁县| 石渠县| 招远市| 尚志市| 庄河市| 万盛区| 泽州县| 余干县| 西华县| 金川县| 泾源县| 武清区| 蛟河市| 淮北市| 丽水市| 南乐县| 建瓯市| 同江市| 鄂托克旗| 杨浦区| 应用必备| 泰州市| 开鲁县| 历史| 郁南县| 新民市| 剑阁县| 什邡市| 富裕县| 浠水县| 疏附县| 南阳市| 金昌市| 高安市| 美姑县| 临江市| 云霄县| 广昌县| 青阳县| 东丰县|