void caHelp(int &res,vector<int> &v,int N,int cnt) { if(cnt==N+1) { ++res; return; } for(int i=1;i<=N;++i) { if(v[i]==0&&(i%cnt==0||cnt%i==0)) { v[i]=1; caHelp(res,v,N,cnt+1); v[i]=0; } } } int countArrangement(int N) { int res=0; vector<int> v(N+1,0); caHelp(res,v,N,1); return res; }
[LeetCode] 526. Beautiful Arrangement
最新推荐文章于 2019-06-10 19:09:28 发布