Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program kewin;
- {uses crt;}
- var
- n,n1,a1,b1,c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1,nn1,o1,p1,q1,r1,ss1,t1,u1,v1,w1,x1,y1,z1,a2,b2,c2,d2,e2,f2,g2,h2,i2,j2,k2,l2,m2,n2,o2,p2,q2,r2,s2,t2,u2,v2,w2,x2,y2,z2: integer;
- s,s1 : string;
- bonus: array[1..26] of integer;
- cost : array[1..26] of integer;
- {Їа®жҐ¤га ўлўҐ¤ҐЁп бва®ЄЁ Ё ҐҐ "бв®Ё¬®бвЁ"
- + § Ї®¬Ё Ґ¬ бва®Єг Ё бв®Ё¬®бвм, Ґб«Ё ® ¬ҐмиҐ а ҐҐ ©¤Ґле}
- procedure output(par:string);
- var sum, i:integer;
- begin
- sum:=0;
- for i := 1 to length(par) do
- sum:=sum + cost[ord(par[i])-96];
- {writeln ('‚ аЁ в :',par,' - ',sum);}
- {Ґб«Ё ¬ЁЁ¬г¬ - § Ї®Ё¬}
- if n1 < 0 then begin n1:=sum; s1:=par; end;
- if sum< n1 then begin n1:=sum; s1:=par; end;
- end;
- {४габЁп! б¬лб« ў ⮬ ,зв® Є ⥪г饩 бва®ЄЁ ¬®¦® ¤®Ў ўЁвм
- б«Ґ¤гойЁ© бЁ¬ў®« Ё§ S , ¬®¦® ЇҐаҐи Јгвм ¤®ЇгбвЁ¬®Ґ § 票Ґ
- Ё в Є ¤ «ҐҐ ,Ї®Є Ґ гЇаҐ¬бп ў Є®Ґж бва®ЄЁ}
- procedure recurs(str:string; pos:integer);
- var i:integer;
- begin
- for i := 1 to bonus[ord(str[length(str)])-96]+1
- do
- if pos+i >= n then
- output(str+s[n])
- else
- recurs(str+s[pos+i],pos+i);
- end;
- begin
- {clrscr;}
- n1 := -1;
- {write('n=');} readln(n);
- {write('s=');} readln(s);
- n:=8;
- s:='abcdebha';
- readln(a2,b2,c2,d2,e2,f2,g2,h2,i2,j2,k2,l2,m2,n2,o2,p2,q2,r2,s2,t2,u2,v2,w2,x2,y2,z2);
- readln(a1,b1,c1,d1,e1,f1,g1,h1,i1,j1,k1,l1,m1,nn1,o1,p1,q1,r1,ss1,t1,u1,v1,w1,x1,y1,z1);
- bonus[1]:=a1 ;bonus[2]:=b1 ;bonus[3]:=c1 ;bonus[4]:=d1 ;bonus[5]:=e1 ;bonus[6]:=f1;
- bonus[7]:=g1 ;bonus[8]:=h1 ;bonus[9]:=i1 ;bonus[10]:=j1;bonus[11]:=k1;bonus[12]:=l1;
- bonus[13]:=m1;bonus[14]:=nn1;bonus[15]:=o1;bonus[16]:=p1;bonus[17]:=q1;bonus[18]:=r1;
- bonus[19]:=ss1;bonus[20]:=t1;bonus[21]:=u1;bonus[22]:=v1;bonus[23]:=w1;bonus[24]:=x1;
- bonus[25]:=y1;bonus[26]:=z1;
- cost[1]:=a2; cost[2]:=b2;cost[3]:=c2;cost[4]:=d2;cost[5]:=e2;cost[6]:=f2;
- cost[7]:=g2; cost[8]:=h2;cost[9]:=i2;cost[10]:=j2;cost[11]:=k2;cost[12]:=l2;
- cost[13]:=m2; cost[14]:=n2;cost[15]:=o2;cost[16]:=p2;cost[17]:=q2;cost[18]:=r2;
- cost[19]:=s2; cost[20]:=t2;cost[21]:=u2;cost[22]:=v2;cost[23]:=w2;cost[24]:=x2;
- cost[25]:=y2; cost[26]:=z2;
- {‘в ав®ў п Ї®§ЁжЁп}
- recurs(s[1],1);
- {writeln;
- writeln('ЋЇвЁ¬ «мл© ў аЁ в: ',s1,' - ',n1);}
- writeln(n1);
- {repeat until keypressed;}
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement