小木棍: http://www.luogu.org/problem/show?pid=1120#  

 

 

   得分:80

                                      

#include <iostream>

using namespace std;

int n,x,total=0,f[61],book[61]={0};

void Input()

{

cin>>n;

int m=0;

for(int i=1;i<=n;i++)

{

cin>>f[i-m];

if(f[i-m]<=50) total=total+f[i-m];

else m++;

}

for(int i=1;i<=60;i++) book[i]=0;

n=n-m;
//please written at here

}

void kuaipai(int* f,int start,int end)
{
int first=start;

int last=end;

int key=f[start];

int train;

while(first<last)

{

while(key<=f[last]&&first<last) last--;

if(first<last)

{

train=f[last];

f[last]=f[first];

f[first]=train;

first++;

}

while(key>=f[first]&&first<last) first++;

if(first<last)

{

train=f[first];

f[first]=f[last];

f[last]=train;

last--;

}

}

train=f[first];

f[first]=key;

key=train;

if(start<first-1) kuaipai(f,start,first-1);

if(last+1<end) kuaipai(f,first+1,end);

}

int search(int sum,int sgin,int counter)

{

if(counter==n&&sgin==sum) return 1;

if(counter==n) return 0;

int a=0;

for(int i=1;i<=n;i++)

{

if(sgin>f[i]&&book[i]==0) { book[i]=1;a=search(sum,sgin-f[i],counter+1);book[i]=0;if(a) return 1;else return 0; }

if(sgin==f[i]&&book[i]==0) { book[i]=1;a=search(sum,sum,counter+1);book[i]=0;if(a) return 1;}

if(sgin<f[i]) return 0;

}

}

void algorithm()

{
kuaipai(f,1,n);

int a=0;

for(int i=f[n];i<=total;i++)

{

if(total%i!=0) continue;

a=search(i,i,0);

if(a) {x=i; return;}

}

}

void Output()

{

cout<<x;

}

int main()

{

Input(); //输入

algorithm(); //算法

Output(); //输出

}

难啊!!查错太惨了

posted on 2016-02-20 21:07  __诗酒趁年华  阅读(183)  评论(0编辑  收藏  举报