123 456 789

#include <iostream>
#include <vector>

using namespace std;

vector<bool> visit(10, false);

bool isOk(int next, int last) {
    if (visit[next]) return false;
    if((next + last)%2==1) return true;
    int mid = (next + last) / 2;
    if(visit[mid]==1) return true;

    int front[] = {1,4,7,1,2,3,1,3};
    int back[] =  {3,6,9,7,8,9,9,7};
    for(int i=0;i<8;i++){
        if((last == front[i] && next ==back[i]) || (last == back[i] && next == front[i]))return false;
    }
    return true;
}

int numberofPath(int last, int len) {
    if (len == 0) return 1;
    int sum = 0;
    for (int next = 1; next <= 9; ++next) {
        if (isOk(next, last)) {
            visit[next] = true;
            sum += numberofPath(next, len - 1);
            visit[next] = false;
        }
    }
    return sum;
}

int main() {
    int cnt = 0;
    for (int len = 4; len <= 9; ++len) {
        visit[1] = true;
        cnt += 4 * numberofPath(1, len - 1);
        visit[1] = false;
        visit[2] = true;
        cnt += 4 * numberofPath(2, len - 1);
        visit[2] = false;
        visit[5] = true;
        cnt += numberofPath(5, len - 1);
        visit[5] = false;
    }
    cout << cnt << endl;
}
全部评论

相关推荐

不愿透露姓名的神秘牛友
昨天 11:21
被夸真的超级开心,好可爱的姐姐
码农索隆:老色批们不用脑补了,我把金智妮的图找来了查看图片
点赞 评论 收藏
分享
码农索隆:想看offer细节
点赞 评论 收藏
分享
Southyeung:我说一下我的看法(有冒犯实属抱歉):(1)简历不太美观,给我一种看都不想看的感觉,感觉字体还是排版问题;(2)numpy就一个基础包,机器学习算法是什么鬼?我感觉你把svm那些写上去都要好一点。(2)课程不要写,没人看,换成获奖经历;(3)项目太少了,至少2-3个,是在不行把网上学习的也写上去。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务