Title Description
Given a positive integer of n columns, the number of columns in one action: the removal of two of a, b, and then add an a × b + 1. Each operation a reduced number of a row, n-1 by the number of operations after only a few columns. Find the maximum value of n-1 in the final thanks to a number of operations.
Enter a description
Input a plurality of sets, each set of two lines, the first line of the input integer n, a second input row n positive integer n <20
Output Description
For each input and output of a last remaining
Sample input
6
8 9 3 6 5 4
Sample Output
29493
Idea: Every time looking for the smallest of multiplying two numbers plus 1, the maximum final result
1 #include<iostream> 2 using namespace std; 3 int main(){ 4 int n; 5 while(cin>>n){ 6 int i,j; 7 unsigned long long m; 8 unsigned long long num[n]; 9 for(i=0;i<n;i++){ 10 cin>>num[i]; 11 } 12 while(n!=1){ 13 for(i=0;i<n-1;i++){ 14 for(j=0;j<n-i-1;j++){ 15 if(num[j]>num[j+1]){ 16 m=num[j]; 17 num[j]=num[j+1]; 18 num[j+1]=m; 19 } 20 } 21 } 22 m=num[0]*num[1]+1; 23 num[0]=m; 24 n--; 25 for(i=1;i<n;i++){ 26 num[i]=num[i+1]; 27 } 28 } 29 cout<<num[0]<<endl; 30 } 31 return 0; 32 }