求NOIP08普及组复赛《选数》的源程序(pascal语言)

2025-03-04 21:55:37
推荐回答(2个)
回答1:

选数是NOIP2002普及的第二题,附我的程序,我们学校的题库:http://pingce.ayyz.cn:9000
望采纳!!!
var
x:array[1..20]of longint;
n,k,i,j,total:integer;
y:array[1..500]of boolean;
procedure find(left,now,all:integer);
begin
if left>n-now+1 then exit;
if (left=0)and(now>n)
then
begin
if y[all] then inc(total);
exit;
end;
find(left,now+1,all);
if left>0 then
find(left-1,now+1,all+x[now]);
end;
begin
readln(n,k);
for i:=1 to n do
read(x[i]);
fillchar(y,sizeof(y),true);
y[1]:=false;
for i:=2 to 500 do
if y[i] then
for j:=2 to 500 div i do y[i*j]:=false;
find(k,1,0);
writeln(total);
end.

回答2:

我没有影响有这道题目啊!