The bug is in my code. Someone has pointed out the error. Please ignore the message. On Fri, Jul 24, 2009 at 9:09 AM, TRaj<tryitn1@xxxxxxxxx> wrote: > hi, > I'm not subscribed to this list. Please add me to your replies. > i've this code at http://codepad.org/L1Ko85ff or below which gives > different answers 8 and 9 (last line) based on optimization (-O2) and > -O0 on my g++ cygwin (3.4). > > When i redefine the min by mymin > #define mymin(a,b) ((a<b)?(a):(b)) it gives me 8 but when i replace it > with std:min it gives me 9 at -O0 on gcc 4.3. > Am i doing something wrong in the below code ? > > #include<cstdio> > #include<iostream> > #include<sstream> > #include<cmath> > #include<cstring> > #include<cstdlib> > #include<cassert> > #include<ctime> > #include<algorithm> > #include<iterator> > #include<iostream> > #include<cctype> > #include<string> > #include<vector> > #include<map> > #include<set> > #include<queue> > #include<list> > using namespace std; > > > > > const int N=7; > int done[1<<12],gdo2[1<<12]; > const int INF=1000000; > > int g(int mask,int lvl){ > assert(mask<(1<<N)); > > printf("MASK=%d\n",mask); > > if(gdo2[mask]) return gdo2[mask]; > > if(lvl==N){ > if(done[mask]) return INF; > return mask; > } > int ans=INF,i; > if(done[mask]==0) ans=mask; > for(i=0;i<N;i++) > if((mask&(1<<i))){ > ans=min(ans,min(g(mask^(1<<i) ,lvl+1),g(mask,lvl+1))); > } > > return gdo2[mask]=ans; > > } > > int main(){ > > done[0]=done[1]=done[3]=done[2]=done[6]=done[4]=done[5]=done[7]=done[15]=1; > > cout <<g(15,0)<<endl; > > return 0; > } >