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 |
大侠们! 指导一下小弟,总是WA,附代码#include <iostream> using namespace std; const int MAXNUM=100; const int MAX=50; short pieces[MAXNUM]; short boxes[MAXNUM]; short distinctBox[MAXNUM]; short valueBox[MAXNUM]; int total=0,boxCount=0; short testnumber=0; short forbidden[MAXNUM+1][MAXNUM];//from 1 to start short forbidCount[MAXNUM+1]={0}; short values=0; short disValueCount=1; short disValue[MAXNUM+1]; int debug=0; void sort(short data[],int number) { short tmp=0; for(int i=0;i<number;++i) { for(int j=i;j<number;++j) { if(data[i]<data[j]) { tmp=data[i]; data[i]=data[j]; data[j]=tmp; } } } disValue[1]=data[0]; for(i=1;i<number;++i) if(data[i]!=data[i-1]) { ++disValueCount; disValue[disValueCount]=data[i]; } } int getValue(short vv) { for(int i=1;i<=disValueCount;++i) { if(disValue[i]==vv) return i; } //return 1; } bool check (int start) { int j,i; if(start==total) return true; short last=0; short tmp; for(j=0;j<boxCount;++j) { for(i=0;i<last;++i) if(valueBox[i]==boxes[j]) break; if(i==last) { distinctBox[last]=j; valueBox[i]=boxes[j]; ++last; } } for(j=0;j<last;++j) { tmp=distinctBox[j]; values=getValue(pieces[start]); for(int z=0;z<forbidCount[values];++z) { if(forbidden[values][z]==boxes[tmp]) break; } if(z<forbidCount[values]) continue; if( (boxes[tmp]+pieces[start]) <= testnumber ) { boxes[tmp]=boxes[tmp]+pieces[start]; if(check(start+1)==false) { boxes[tmp]=boxes[tmp]-pieces[start]; values=getValue(pieces[start]); debug=forbidCount[values]; forbidden[values][debug]=boxes[tmp]; forbidCount[values]=debug+1; } else return true; } } return false; } int main(int argc, char* argv[]) { int results[300]={0}; int i; int sum,biggest; cin>>total; int count=0; while(total!=0) { sum=0; biggest=1; count=0; for( i=0;i<total;++i) { cin>>pieces[count]; if((pieces[count]>MAX)||(pieces[count]<=0)) continue; sum=sum+pieces[count]; if(pieces[count]>biggest) biggest=pieces[count]; ++count; } total=count; disValueCount=1; sort(pieces,total); for(i=biggest;i<=sum;++i) { if(sum%i!=0) continue; boxCount=sum/i; for(int m=0;m<boxCount;++m) boxes[m]=0; testnumber=i; values=1; for(int mm=1;mm<=MAXNUM;++mm) forbidCount[mm]=0; if(check(0)) { ++results[0]; results[results[0]]=i; break; } } cin>>total; } for(int j=1;j<=results[0];++j) cout<<results[j]<<endl; //cin>>total; return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator