博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
方格填数
阅读量:4521 次
发布时间:2019-06-08

本文共 851 字,大约阅读时间需要 2 分钟。

如下的10个格子

填入0~9的数字。要求:连续的两个数字不能相邻。

(左右、上下、对角都算相邻)

一共有多少种可能的填数方案?

请填写表示方案数目的整数。

注意:你提交的应该是一个整数,不要填写任何多余的内容或说明性文字。

答案6 (15分)

 

代码:

#include 
#include
#include
#include
using namespace std;int dir[10][4] = {
1,3,4,5,2,4,5,6,5,6,-1,-1, 4,7,8,-1,5,7,8,9,6,8,9,-1, 9,-1,-1,-1,8,-1,-1,-1,9,-1, -1,-1,-1,-1,-1,-1};bool check(int *a) { for(int i = 0;i < 10;i ++) { for(int j = 0;j < 4;j ++) { if(dir[i][j] != -1 && abs(a[i] - a[dir[i][j]]) == 1) return false; } } return true;}int main() { int c = 0; int a[10] = {
0,1,2,3,4,5,6,7,8,9}; do { if(check(a)) c ++; } while(next_permutation(a,a + 10)); printf("%d",c);}

 

转载于:https://www.cnblogs.com/8023spz/p/10440573.html

你可能感兴趣的文章
javascript 日常
查看>>
Android打开相机进行人脸识别,使用虹软人脸识别引擎
查看>>
打印沙漏
查看>>
腾讯物联TencentOS tiny上云初探
查看>>
nginx 安装
查看>>
C#中upd分包与发送,已经实现全部代码
查看>>
让插件帮你优化代码
查看>>
学习笔记3
查看>>
LeetCode 20. Valid Parentheses
查看>>
LeetCode 4 Keys Keyboard
查看>>
bean找不到异常
查看>>
重拾Javascript基础(三) - DOM属性&方法
查看>>
电感在电路中的作用(硬件01)
查看>>
ng 动态的生成option。
查看>>
ORACLE-12C-RAC INSTALL
查看>>
LintCode-Topological Sorting
查看>>
自定义引用类型的Enumerable.Union调用(原创)
查看>>
Keil c中自定义带可变参数的printf函数
查看>>
抽象类实例
查看>>
react context prop-types
查看>>