function [weight,vars]=nxtseqdf(vars,n)

p = length(vars);

for vc=p:-1:1
    if vars(vc) < n
        vars(vc) = vars(vc)+1;
        vars(vc+1:p) = vars(vc);
        break;
    else
        if vc == 1
            vars = [];
        end;
    end;
end;

dfs = diff([vars inf]);
dfs = find(dfs>0);
dfs = diff([0 dfs]);
dfs = prod(factorial(dfs));
weight = factorial(p)/dfs;