2 回答
TA贡献1860条经验 获得超9个赞
var dp:array[0..100000]of longint;
a:array[0..11]of longint;
sum,i,v,j,k,cnt,cas
begin
cas:=1;
while (not eoln) do
begin
read(a[1]);
sum:=a[1];
for i:=2 to 6 do
begin
read(a[i]);
sum:=sum+i*a[i];
end;
if (sum=0) break;
writeln("Collection #%d:",cas++);
if(sum mod 2=1)
begin
writeln("Can't be divided.");
continue;
end;
v:=sum div 2;
fillchar(dp,0,sizeof(dp));
dp[0]:=1;
for i:=1 to 6 do
begin
if(a[i]=0) continue;
j=1;
while (j<=a[i]) do
begin
cnt:=j*i;
for k:=v downto cnt do
if(dp[k-cnt]) dp[k] = 1;
a[i]=a[i]-j;
j:=j*2;
end;
cnt:=a[i]*i;
if (cnt=1)
begin
for k:=v downto cnt do
if (dp[k-cnt]=1) dp[k]=1;
end;
end;
if (dp[v]=1) writeln("Can be divided.")
else writeln("Can't be divided.\n\n");
end;
end.
自己改一下吧,没有编译器,sorry了,不会的问我
- 2 回答
- 0 关注
- 824 浏览
添加回答
举报