Re: [理工] [軟設]-中正96-資工

看板Grad-ProbAsk作者 (石斛蘭)時間14年前 (2010/03/23 22:01), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/2 (看更多)
※ 引述《alibudaken (最後掙扎J)》之銘言: : 12. : (a) Given an array A of N positive integers and an integer M : write a recursive C function : int sos(int A[], int N, int M) : which returns 1 if there exists a subset of numbers in A : whose sum is equal to M and returns 0 otherwise. : Your function should not exceed 15 statements. : 是用類似Dynamic programming的概念去找嗎? : 想了想還是想不出來...OTL : 請幫忙解惑<(_ _)> : 謝謝!! int sos(int A[], int N, int M) { if( N==1 ){ return (A[0]==M); } else{ return ( sos(A+1, N-1, M-A[0]) || sos(A+1, N-1, M) ); } } 大概是這樣 :) -- 人家可不是為了你才這樣做的哦! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 60.198.35.85

03/23 23:58, , 1F
請問A[0]用途是什麼@@?
03/23 23:58, 1F
A[0]就是Array的第一個element ※ 編輯: dendrobium 來自: 60.198.35.85 (03/24 07:58)
文章代碼(AID): #1BgCcbSs (Grad-ProbAsk)
文章代碼(AID): #1BgCcbSs (Grad-ProbAsk)