Pls some1 tell me what 's the TEST#1
my brute force program... works for all cases ...
still getting WA 1..
#include<stdio.h>
long min = 1000000000;
void recur(int arr[] , int n , int finished[] , int finishedCount , int total , long damage)
{
int i , k , l , sum , tempfinishedCount , flag , a, b , c;
if( finishedCount == n )
{
if( damage < min ) min = damage; return ;
}
if( damage > min ) return ;
for( i = 0 ; i < n ; i++ )
{
k=(i+1)%n; l=(k+1)%n; sum=0; tempfinishedCount=finishedCount; flag = 0;
if( !(a=finished[i]) ){ finished[i] = 1; finishedCount++; sum+=arr[i]; flag=1; }
if( !(b=finished[k]) ){ finished[k] = 1; finishedCount++; sum+=arr[k]; flag=1; }
if( !(c=finished[l]) ){ finished[l] = 1; finishedCount++; sum+=arr[l]; flag=1; }
if(!flag) continue;
total -= sum; damage+= total;
recur( arr , n , finished , finishedCount ,total , damage );
damage-=total; total += sum;
finished[i]=a; finished[k]=b; finished[l]=c; finishedCount=tempfinishedCount;
}
}
int main()
{
int n , i ,arr[21] , finished[21]={0} , finishedCount = 0 , total;
scanf("%d",&n);
for( i = 0 ; i < n ; i++ )
{ scanf("%d",&arr[i]); total+=arr[i]; }
if( n <=3 ) printf("0\n");
else
{
recur( arr , n , finished , finishedCount , total , 0 );
printf("%ld\n",min);
}
return 0;
}