11059 Maximum Product
題目:http://luckycat.kshs.kh.edu.tw/homework/q11059.htm
觀念:bruteforce (DFS)
難度:luckycat ★
#include <iostream>
#include <string.h>
using namespace std;
int N;
long long arr[20], answer ;
void DFS( int now , long long product ){
if ( product > answer )
answer = product;
if ( now == N )
return;
DFS( now+1 , product * arr[now] );
}
int main(){
int c = 1;
while ( cin >> N ){
for ( int i = 0 ; i < N ; i++ )
cin >> arr[i];
answer = 0;
for ( int str = 0 ; str < N ; str++ )
DFS( str+1 , arr[str] );
cout << "Case #" << c++ << ": The maximum product is " << answer << "." << endl;
cout << endl;
}
return 0;
}