蓝桥杯国赛白给记
A310电脑就离谱,明年去北京再战吧
持续更新ing
最后一道填空题:
hp DFS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | #include<bits/stdc++.h> using namespace std; int N; bool vis[6][6]; int ans = 0; int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; bool check() { for ( int i = 1; i <= N; ++i) { for ( int j = 1; j <= N; ++j) { if (!vis[i][j]) { return 0; } } } return 1; } void DFS( int x, int y) { //cout << x << " " << y << endl; if (x <= 0 || y <= 0 || x > N || y > N) { return ; } if (check()) { ans++; return ; } for ( int i = 0; i < 4; ++i) { int xx = x + dir[i][0]; int yy = y + dir[i][1]; if (!vis[xx][yy]) { vis[xx][yy] = 1; DFS(xx, yy); vis[xx][yy] = 0; } } } int main () { while (cin >> N) { ans = 0; memset (vis, 0, sizeof vis); for ( int i = 1; i <= N; ++i) { for ( int j = 1; j <= N; ++j) { memset (vis, 0, sizeof vis); vis[i][j] = 1; DFS(i, j); } } cout << ans << endl; } } |
经验:用notepad配环境或者用命令行直接编译运行(g++ sbA310.cpp -> a.exe)死循环ctrl c终止
作者:LightAc
出处:https://www.cnblogs.com/lightac/
联系:
Email: dzz@stu.ouc.edu.cn
QQ: 1171613053
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。
出处:https://www.cnblogs.com/lightac/
联系:
Email: dzz@stu.ouc.edu.cn
QQ: 1171613053
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步