|
错在哪?
- #include<iostream>
- int sum,f[9];
- bool a[16],b[9],c[16];
- using namespace std;
- int dfs(int step);
- void print();
- int main()
- {
- dfs(1);
- return 0;
- }
- int dfs(int step)
- {
- int i;
- for(i=1;i<=8;i++)
- {
- if((!a[i])&&(!b[i+step])&&(!c[i-step+7]))
- {
- f[step]=i;
- a[i]=true;
- b[i+step]=true;
- c[step-i+7]=true;
- if(i==8)
- {
- print();
- }
- else
- {
- dfs(step+1);
- }
- a[i]=false;
- b[i+step]=false;
- c[step-i+7]=false;
- }
- }
- }
- void print()
- {
- int i;
- sum++;
- cout<<"sum="<<sum<<endl;
- for(i=1;i<=8;i++)
- {
- cout<<f[i];
- }
- cout<<endl;
- }
复制代码 |
上一篇: 【实用C++】零基础入门教程35课strlen单步调试疑问!下一篇: 我用PostMessage最小化后,发现SetTimer用不了了,请问咋解决?
|