解题思路:
注意事项:
参考代码:
#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 人评分
Tom数 (C++代码)浏览:825 |
C语言程序设计教程(第三版)课后习题5.7 (C++代码)浏览:846 |
C语言程序设计教程(第三版)课后习题8.3 (C语言代码)浏览:624 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:578 |
【魔板】 (C++代码)(时间超限,希望会的帮我改正一下)浏览:738 |
母牛的故事 (C语言代码)浏览:549 |
图形输出 (C语言代码)浏览:1375 |
C二级辅导-求偶数和 (C语言代码)浏览:671 |
The 3n + 1 problem (C语言代码)浏览:501 |
C语言程序设计教程(第三版)课后习题12.3 (C语言代码)浏览:542 |