243854232
243854232
关注数: 5
粉丝数: 10
发帖数: 818
关注贴吧数: 8
安徽四校粤语歌唱比赛需要赞助,能提供舞台或赞助费用高的赞助商 安徽四校粤语歌唱比赛需要赞助,能提供舞台或赞助费用高的赞助商联系我 2696038873
现金赞助,只需注册。请联系2696038873 现金赞助,只需注册。请联系2696038873
请问这是什么意思 dist[i]:=cost[0,i]; if dist[i]<>max then path[i]:=path[i]+[i]; end;
关于数组定义问题 cost:array[0..n,0..n]of integer=((max,max,10,max,30,100),(max,max,5,max,max,max),(max,max,max,50,max,max),(max,max,max,max,max,10),(max,max,max,20,max,60),(max,max,max,max,max,max));{数组赋初值} 这个是什么意思?
还是哈夫曼树,大家看看 program haffmantree; const m=100;leaf=30;maxnode=leaf*2-1; type node=record weight,t,ld,rd:integer; end; treetype=array[0..maxnode] of node; var procedure creathuffmantree(var treenode:treetype); var i,j,m1,m2,x1,x2,n:integer; begin readln(n); for i:=0 to 2*n-1 do begin treetype[i].weight=0; treetype[i].t=-1; treetype[i].ld=-1; treetype[i].rchild=-1; end; for i:=0 to n-1 do read(treetype[i].weight); for i:=0 to n-1 do begin m1:=m; m2:=m; x1:=0; x2:=0; for j:=0 to n+i-1 do if (treetype[j].weight<m1) and (treetype[j].t=-1) then begin m2:=m1; x2:=x1; m1:=treetype[j].weight; x1:=j; end; else if (treetype[j].weight<m2) and (treetype[j].t=-1) then begin m2:=treetype[j].weight; x2:=j; end; treetype[x1].t:=n+i; treetype[x2].t:=n+i; treetype[n+i].weight:=treetype[x1].weight+treetype[x2].weight; treetype[n+i].ld:=x1; treetype[n+i].rd:=x2; end; writeln(treetype[n+i]); end.
建huffmantree,能帮我看看这程序错哪里了吗? program tree; const m=100; type node=record data:integer; addr,lchild,rchild:0..m; end; treetype=array[1..m] of node; var a,b:treetype; i,t,x,l,r:integer; procedure insort(a,n); begin for i:=1 to n-1 do for j:=i+1 to n do if a[i].data<a[j].data then begin x:=a[j].data;a[j].data:=a[i].data;a[i].data:=x; l:=a[j].lchild.data;a[j].lchild.data:=a[i].lchild.data;a[i].lchild.data:=l; r:=a[j].rchild.data;a[j].rchild.data:=a[i].rchild.data;a[i].rchild.data:=r; end; end; procedure createhuffmantree(a,b,t,n); var i:integer; begin for i:=1 to n do begin b[i].data:=a[i].data; b[i].lchild.data:=o; b[i].rchild.data:=0; end; t:=n+1; i:=n; while i>=2 then begin insort(a,i); b[t].data:=a[1].data+a[2].data; b[t].addr:=t; a[1].data:=b[t].data; a[1].addr:=t; a[2].data:=a[i].data; a[2].data:=a[i].addr; i:=i+1; t:=t-1; end; writeln createhuffmantree(a,b,t,n); end.
1
下一页