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 |
题目意思不明确,大牛指点一下,求什么木棍可以翻转吗,3个不能有公共点,还是任意两个都不能有#include <iostream> #include <memory.h> #include <algorithm> using namespace std; const int maxlen=25+1; const int maxv=13+1; int visited[maxlen*maxv+1],n; int maxlength,len[maxv],partlen[4],ending,sum[4]; int search(int index); int main() { int testcase=0; while (cin>>n && n>0) { testcase++; maxlength=0; ending=0; for (int i=1;i<=n;i++) { cin>>len[i]; ending+=len[i]; } ending=ending/3; memset(visited,0,sizeof(visited)); memset(partlen,0,sizeof(partlen)); memset(sum,0,sizeof(sum)); search(1); cout<<"Case "<<testcase<<": "<<maxlength<<endl; } return 0; } int search(int index) { if (index==n) { int p=0,t=0; p=1; if (partlen[2]<partlen[p]) p=2; if (partlen[3]<partlen[p]) p=3; sum[p]++; partlen[p]+=len[index]; t=abs(partlen[3]-partlen[1])+abs(partlen[3]-partlen[2]); if (t==0 && partlen[1]>maxlength && sum[1]>1 && sum[2]>1 && sum[3]>1) { maxlength=partlen[1]; } partlen[p]-=len[index]; sum[p]--; return 0; } int k,temp; int cansearch[3]={1,1,1}; if (partlen[1]==partlen[2]) { cansearch[1]=0; if (partlen[2]==partlen[3]) cansearch[2]=0; } else { if (partlen[1]==partlen[3]) cansearch[2]=0; if (partlen[2]==partlen[3]) cansearch[2]=0; } for (k=1;k<=3;k++) if (cansearch[k-1]) { partlen[k]+=len[index]; sum[k]++; if (partlen[k]<=ending) switch (visited[partlen[k]]%10) { case 0: { visited[partlen[k]]=1; search(index+1); visited[partlen[k]]=0; break; } case 1: { visited[partlen[k]]=2; search(index+1); visited[partlen[k]]=1; break; } case 2: { if (partlen[k]>maxlength && sum[1]>1 && sum[2]>1 && sum[3]>1) { maxlength=partlen[k]; } break; } } partlen[k]-=len[index]; sum[k]--; } search(index+1); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator