计数凸四边形

时间:2014-11-18 14:28:20

标签: matlab combinations combinatorics

在网格3x3中,我们有1038个凸四边形,已知形式oeis。我计算的答案是912。

我的方法:

我计算网格中小于或等于3x3的凸四边形的数量,其中所有点都在较小网格的边界上。然后乘以系数。该系数是较小网格可以放置在较大网格中的方式的数量。例如,网格1x1可以放置9次,网格2x1可以放置6次。

我的代码:

n=3;
exclusive1=zeros(n,n);

for i=1:n
    for j=1:n
        exclusive1(i,j)=exclusive2(i,j);
    end
end
total=0;
for i=1:n
    for j=1:n
        total=total+ exclusive1(i,j)*(n-i+1)*(n-j+1);

    end
end
total

exclusive2:

function [y ] = exclusive2( ni,nj )

M=max(ni,nj);
m=min(ni,nj);
% corner not selected
sum0=0;
sum0=(M-1)*(M-1)*(m-1)*(m-1);
sum0

% one corner is chosen
sum1=0;
sum1=(M-1)*(m-1)*(M+m-2)*4; % one on side 1, one on side 2, one on side 3 or 4
if M>=3
    sum1=sum1+nchoosek(M-1,2)*(m-1)*4; % two on side 1, one on side 2
end
if m>=3
    sum1=sum1+nchoosek(m-1,2)*(M-1)*4; % two on side 2, one on side 1
end
sum1

% two corners are chosen
% corners are on same side
sum21=0;
sum21=(M-1)* 2*(m-1)*4;  % the 4 because 4 ways to select same side corners
                         % one on side 1 and one on side 2 or 3
if M>=3
    sum21=sum21+2*nchoosek(M-1,2); % two on side 1
end
if m>=3
    sum21=sum21+2*nchoosek(m-1,2); % two on side 2
end
sum21

% two corners are chosen
% different side
sum22=0;
sum22=(M-1)*(m-1)*2*2;  % picking two pts from one side of diagonal
                        % first *2 because diagonal splits it into two side
                        % second *2 because we can pick two pairs of different side corners
sum22=sum22+(M+m-2)*(M+m-2)*2;  
sum22

% three cor;ners
sum3=0;
sum3=4*(M-1+m-1);
sum3

% four corners
sum4=0;
sum4=1;

y=sum0+sum1+sum21+sum22+sum3+sum4;
end

请帮忙。

0 个答案:

没有答案