解题思路:
注意事项:
参考代码:
#include <iostream> #include <algorithm> using namespace std; int n, k; int height[12]; bool tag[12]; int result = 0; void dfs(int lay, int pre_height){ if(lay == n){//lay是x,说明前x层已经找好了,而不是将要找第x层!!! if(abs(height[1] - pre_height) <= k){ result++; } return ; } for(int i = 1;i<=n;i++){ if(tag[i] == false && abs(height[i] - pre_height) <= k){ tag[i] = true; dfs(lay + 1, height[i]); tag[i] = false; } } return; } int main(){ cin>>n>>k; for(int i=1;i<=n;i++){ cin>>height[i]; } tag[1] = true; dfs(1, height[1]); cout<<result; return 0; }
0.0分
0 人评分
【回文数(二)】 (C语言代码)浏览:856 |
C语言训练-计算1~N之间所有奇数之和 (C语言代码)浏览:655 |
C语言程序设计教程(第三版)课后习题9.10 (C语言代码)浏览:557 |
局部变量作函数返回值的问题浏览:981 |
矩形面积交 (C语言代码)浏览:1313 |
整除问题 (C语言代码)浏览:526 |
拆分位数 (C语言代码)浏览:522 |
分解质因数 (C++代码)浏览:1482 |
C语言程序设计教程(第三版)课后习题9.8 (C语言代码)浏览:531 |
幸运数 (C++代码)浏览:2871 |