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 |
高手帮忙看看,什么bt数据都通过了,但是最后还是wa!#include <iostream> #include <algorithm> #include <functional> using namespace std; int tc; int isUsed[64]; int length[64]; int pp[64]; int pp_count[64]; #define max(a,b) (((a) > (b)) ? (a) : (b)) bool isOK(int l,int sum,int start,int deep) { if (deep>50) return false; for(int i=start;i<tc;i++) { if (isUsed[i]==0) continue; if (sum+pp[i]==l) { isUsed[i]--; return true; }else if(sum+pp[i]<l){ isUsed[i]--; if (isOK(l,sum+pp[i],i,deep+1)) { return true; } isUsed[i]++; }else if(sum+pp[i]>l){ continue; } } return false; } void main() { int i,j; scanf("%d",&tc); int maxStick; int sumStick; int flag = false; int start; while(tc!=0) { maxStick = 0; sumStick = 0; for(i=0;i<tc;i++) { scanf("%d",&length[i]); maxStick = max(maxStick,length[i]); sumStick += length[i]; } flag = false; sort(length,length+tc,greater<int>()); pp[0] = length[0]; pp_count[0] = 1; j = 0; for(i=1;i<tc;i++) { if(length[i] == pp[j]) { pp_count[j]++; }else{ pp[++j] = length[i]; pp_count[j] = 1; } } tc = j + 1; for(j=maxStick;j<=sumStick;j++) { if (sumStick%j!=0) continue; if (j==sumStick) { printf("%d\n",j); break; } start = 0; st: memcpy(isUsed,pp_count,tc*sizeof(int)); flag = isOK(j,0,start,0); if(!flag) { continue; } for(i=0;i<sumStick/j - 2;i++) { flag = isOK(j,0,0,0); if(!flag) { start++; goto st; } } if (flag) { printf("%d\n",j); break; } } scanf("%d",&tc); } return; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator