解题思路:
注意事项:
参考代码:
#include<iostream> #include<algorithm> #include<cstring> #include<cmath> #include<queue> #include<cctype> #include<cstdlib> using namespace std; char *sz,*line; int count1 = 0; int n; bool judge(char a,int n) { for(int i=1;i<n;i++) { if(line[i] == a) return false; } return true; } void dfs(int t) { if(t<=n){ for(int j=1;j<n;j++) { if(judge(sz[j],t)) { if(line[t-1]-sz[j]>=-2&&line[t-1]-sz[j]<=2) { line[t] = sz[j]; if(t==n-1) {count1++;} dfs(t+1); } } } } } int main() { cin>>n; sz = new(char [n+1]); line = new(char [n+1]); line[0] = '1'; int i = 0; for(char t='1';i<n;i++,t++) {sz[i] =t;line[i+1] = '\0';} sz[n] = '\0'; dfs(1); cout<<count1; return 0; }
0.0分
0 人评分
求圆的面积 (C++代码)这里推荐使用宏定义浏览:1911 |
C二级辅导-计负均正 (C语言代码)浏览:581 |
C语言程序设计教程(第三版)课后习题7.3 (C语言代码)浏览:1118 |
母牛的故事 (C语言代码)浏览:1300 |
A+B for Input-Output Practice (IV) (C++代码)浏览:677 |
A+B for Input-Output Practice (VI) (C++代码)浏览:418 |
上车人数 (C语言代码)浏览:781 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:560 |
兰顿蚂蚁 (C++代码)浏览:1046 |
简单的a+b (C语言代码)浏览:632 |