为什么就算不出来?是一道算法问题 感到纠结

今有7对数字:两个1,两个2,两个3,...两个7,把它们排成一行。
要求,两个1间有1个其它数字,两个2间有2个其它数字,以此类推,两个7之间有7个其它数字。如下就是一个符合要求的排列:

17126425374635

当然,如果把它倒过来,也是符合要求的。

请你找出另一种符合要求的排列法,并且这个排列法是以74开头的。

注意:只填写这个14位的整数,不能填写任何多余的内容,比如说明注释等。#include
#include
int a[14],c[14];
void paixu(int x){
if(x==0||x==1||x==8||x==6){paixu(x+1);}
if(x>=14){
for(int i=0;i int b=i+1+a[i];
if(b>=14){ b=i-a[i]-1;
if(a[i]!=a[b]) return ;
}
if(b<14) if(a[i]!=a[b]) return ;

        }
       for(i=0;i<14;i++)
           printf("%d",a[i]);

}

for(int b=1;b<=14;b++)
    for(int i=1;i<=7;i++){
    if(!c[b]){
    a[x]=i;
    c[b]=1;
    paixu(x+1);
    c[b]=0;
    }
}   

}

int main(){
memset(a,0,sizeof(a));
memset(c,0,sizeof(c));
a[0]=7,a[1]=4,a[8]=7,a[6]=4;
c[0]=1,c[1]=1,c[8]=1,c[6]=1;
paixu(1);

return 0;
}


又是那个傻桥出的馊题,用C#写一个,反正你只要答案

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            foreach (var item in foo("74"))
                Console.WriteLine(item);
        }
        static IEnumerable<string> foo(string current)
        {
            if (current.Length == 14)
            {
                yield return current;
            }
            else
            {
                var query = Enumerable.Range(1, 7).Select(x => current + x.ToString())
                    .Where(y =>
                    {
                        var chars = y.Select((z, i) => new { z, i })
                            .GroupBy(z => z.z);
                        return chars.All(z => z.Count() < 3 && (z.Last().i - z.First().i - 1) == (z.Count() == 2 ? z.Key - '0' : -1));
                    });
                foreach (string s in query)
                    foreach (string s1 in foo(s))
                        yield return s1;
            }
        }
    }
}

74151643752362
Press any key to continue . . .