📄 4473853_tle.cpp
字号:
#include<iostream>
#include<algorithm>
using namespace std;
int length[65];//棍子长度
int max_length;//最长棍子
int sum;//总长度
int now[65][65];//搜索状态
bool used[65];//是否已经使用
int finish[65];//搜索成功棍子数
int zero[64];//空的棍子数
int number;//棍子数
int n;//搜索棍子数
int goal;//目标棍子长度
bool ok;//是否成功
//int stop;//test
bool get(int l)
{
for(int count=1;count<=number;count++)
{
if(!used[count]&&length[count]<=l)
{
if(length[count]==l){used[count]=true;return true;}
else if(get(l-length[count])) return true;
else return false;
}
}
return false;
}
void slove(int p)//p 搜索到第几个棍子
{
if(ok) return;
if(p==n) {ok=true;return;}
int now=goal;
if(get(goal)) slove(p+1);
}
bool bijiao(int a,int b)
{return a>b;}
int get_next()
{
int count;
for(count=goal;count<=sum;count++)
{
if(sum%count==0) break;
}
return count;
}
int main()
{
int first=true;
while(1)
{
cin>>number;
if(number==0) return 0;
memset(length,0,sizeof(length));
memset(now,0,sizeof(now));
memset(zero,0,sizeof(zero));
memset(finish,0,sizeof(finish));
n=0;
max_length=0;
sum=0;
for(int count=1;count<=number;count++)
{
cin>>length[count];
sum+=length[count];
if(length[count]>max_length) max_length=length[count];
}
sort(length+1,length+1+number,bijiao);
goal=max_length;
while(1)
{
ok=false;
goal=get_next();
if(goal==sum+1) break;
n=sum/goal;
zero[0]=n;
memset(used,false,0);
slove(1);
if(ok)
{
if(first) cout<<goal;
else cout<<endl<<goal;
break;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -