Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
different result on different OJZOJ: WA POJ: AC Is the test data different or the check program different? this is my submit: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #include <cstdio> #include <cstring> #include <string> #include <iostream> #define MAXL 100 using namespace std; int opt[MAXL+1][MAXL+1]; string text; string opt_str[MAXL+1][MAXL+1]; int solve(int s,int l){ int min=2e9,temp; string min_str; if(opt[s][l]!=-1) return opt[s][l]; if(text[s]=='('&&text[s+l-1]==')' || text[s]=='['&&text[s+l-1]==']'){ temp=solve(s+1,l-2); if(temp<min){ min=temp; if(text[s]=='(') min_str="("+opt_str[s+1][l-2]+")"; else min_str="["+opt_str[s+1][l-2]+"]"; } } if(text[s]=='('){ temp=solve(s+1,l-1)+1; if(temp<min){ min=temp; min_str="("+opt_str[s+1][l-1]+")"; } } if(text[s]=='['){ temp=solve(s+1,l-1)+1; if(temp<min){ min=temp; min_str="["+opt_str[s+1][l-1]+"]"; } } if(text[s+l-1]==')'){ temp=solve(s,l-1)+1; if(temp<min){ min=temp; min_str="("+opt_str[s][l-1]+")"; } } if(text[s+l-1]==']'){ temp=solve(s,l-1)+1; if(temp<min){ min=temp; min_str="["+opt_str[s][l-1]+"]"; } } for(int i=1;i<l;++i){ temp=solve(s,i)+solve(s+i,l-i); if(temp<min){ min=temp; min_str=opt_str[s][i]+opt_str[s+i][l-i]; } } opt[s][l]=min; opt_str[s][l]=min_str; return min; } void init(){ memset(opt,-1,sizeof(opt)); for(int i=0;i<=text.length();++i){ opt[i][0]=0; opt_str[i][0]=""; } } int main(){ char buffer[MAXL+2]; while(fgets(buffer,MAXL+2,stdin)){ text=string(buffer,buffer+strlen(buffer)-1); if(buffer[0]=='\n'){ cout<<endl; continue; } init(); solve(0,text.length()); cout<<opt_str[0][text.length()]<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator