JavaScript(E6)79 82
F=(n,t,
  d=n+n*~-n/4-t/2,
  l=1,
  q=[for(x of Array(n))d<n--?++l:(d+=~n,--l)]
)=>d?[]:q
无需蛮力或枚举所有元组。
见长度的序列ñ作为Ñ -1步,每步为递增或递减。
请注意,您只能将一个增量换为一个减量,其总和为2,因此对于任何给定的长度,总和始终为偶数或始终为奇数。
具有所有增量,序列为0、1、2、3,...,n-1,我们知道总和为(n-1)* n / 2 
更改最后一步,总和改变2,因此最后一步的权重为2。
更改最后一步的权重为4,因此最后一步的权重为4。这是因为后续步骤基于到目前为止的部分总和。
更改上一步,总和更改为6,因此最后一步的权重为6(不是8,这不是二进制数字)。
... 
更改第一步的重量为(n-1)* 2  
算法
Find the max sum (all increments)  
Find the difference with the target sum (if it's not even, no solution)  
Seq[0] is 0  
For each step  
  Compare current difference with the step weight
  if is less 
     we have an increment here, seq[i] = seq[i-1]+1 
  else 
     we have a decrement here, seq[i] = seq[i-1]-1.  
     Subtract we current weight from the current diff.
If remaining diff == 0, solution is Seq[]. Else no solution
非高尔夫代码
F=(len,target)=>{
  max=(len-1)*len/2
  delta = max-target
  seq = [last=0]
  sum = 0
  weight=(len-1)*2
  while (--len > 0)
  {
    if (delta >= weight)
    {
      --last
      delta -= weight;
    }
    else
    {
      ++last
    }  
    sum += last
    seq.push(last);
    weight -= 2;
  }  
  if (delta) return [];
  console.log(sum) // to verify
  return seq
}
在Firefox / FireBug控制台中测试
F(8,4)
输出量
[0, -1, 0, -1, 0, 1, 2, 3]
               
              
(l-1)*l/2并且-(l-1)*l/2具有与相同的奇偶校验(l-1)*l/2。