1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
| function [result, celue] = touzi(data, mmax, n)
if nargin == 1
disp([data(1,:)])
for i=2:size(data,1)
tm=zeros(i,size(data,2));
for j=1:size(data,2)
[r,c]=touzi(data, j, i);
tm(1,j)=r;
tm(2:length(c)+1,j)=c.';
end
disp("f"+(i-1))
disp(tm(1,:))
disp(tm(2:i,:))
end
[result, celue] = touzi(data, size(data,2),size(data,1));
return
end
if n==1
result=0;
celue=[];
return
end
if mmax==0
result=0;
celue=zeros(1,n-1);
return
end
result=0;
celue=0;
for i=0:mmax
[r,c]=touzi(data, i, n-1);
f=data(n,:);
if mmax-i==0
if r>result
result=r;
celue=[c 0];
end
else
if r+f(mmax-i)>result
result=r+f(mmax-i);
celue=[c mmax-i];
end
end
end
|