合計は、すべてのシーケンスに値するものです.

1283 ワード

問題:
Write a function that tas s s s ararray of five integers,each of which is between 1 and 10,and returns the number of commbination of those integers to 15.Foxample,caling the funcncncwith the arary,rale,5,1,5,1,1,1,5,5,1,1,3,5,5,1,1,3,5,3,3,1,3,3,6.5+10、5+5+2+3、10+2+3)
分析:
組み合わせ問題
int ExpectedSumSequence(int* pData, int len, int sum){
	int seqCount = 0;
	if (len==0 && sum==0){
		seqCount = 1;
	} else if (len>0){
		//                                       
		seqCount = ExpectedSumSequence(pData+1, len-1, sum-pData[0])+ExpectedSumSequence(pData+1, len-1, sum);
	}
	return seqCount;
}
条件を満たすすべてのシーケンスを印刷する必要がある場合:
static int ExpectedSumSequence(int* pData, int start, int end, bool contained[], int expectedSum){
	int seqCount = 0;
	if (start==end && expectedSum==0){
		seqCount = 1;
		for (int i=0; i
問題:
Give a set of n integers、each in the range 0:K、partition the integers in to to subsets to minimize S 1-S 2|、where S 1 and S 2 denote the sums of the elements.