ZOJ 1002
来源:互联网 发布:海通大智慧软件下载 编辑:程序博客网 时间:2024/04/29 07:49
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1002
浙江大学acm judge online 1002
一看这题目,在算法书看到过,而且数据也不是太大,就算枚举也根本不会超时
一想,可以采用回溯法,谁知上网一查,基本上都采用了回溯法
浙江大学acm judge online 1002
一看这题目,在算法书看到过,而且数据也不是太大,就算枚举也根本不会超时
一想,可以采用回溯法,谁知上网一查,基本上都采用了回溯法
下面是AC的C代码:#include < stdio.h>char map[4][4];int best,n;int P(int row, int col)//判断在row,col处是否可以放;{ int i; for (i = row - 1; i >= 0; i--) { if (map[i][col] == 'O') return 0; if (map[i][col] == 'X') break; } for (i = col - 1; i >= 0; i--) { if (map[row][i] == 'O') return 0; if (map[row][i] == 'X') break; } return 1; }void solve(int k,int tot){ int x,y; if(k==n*n)//如果到了最后,找出最大的可能值; { if(tot>best) { best=tot; return; } } else { x = k / n; y = k % n; if((map[x][y] == '.') && (P(x,y) ) ) { map[x][y] = 'O'; solve(k + 1,tot + 1); map[x][y] = '.';//回溯; } solve(k + 1,tot); }}int main(){ int i,j; while(scanf("%d",&n)!=EOF) { for(i = 0;i < n;i++) for(j = 0;j < n;j++) scanf("%1s",&map[i][j]); /*输入单个字符并且忽略空白*/ best=0; solve(0,0); printf("%d\n",best); } return 0;}
- ZOJ 1002
- ZOJ 1002
- zoj 1002
- ZOJ 1002
- ZOJ 1002
- zoj 1002
- zoj-1002
- zoj 1002
- ZOJ 1002
- ZOJ-1002
- ZOJ 1002
- ZOJ-1002
- ZOJ 1002
- ZOJ 1002
- zoj-1002
- ZOJ 1002
- ZOJ 1002
- ZOJ-1002
- POJ1702Eva's Balance
- 多线程的条件变量
- 敏捷开发“松结对编程”实践之五:代码检查篇(大型研发团队,学习型团队,139团队,师徒制度,代码审查)
- 湖南师大acm10015
- android 动画笔记
- ZOJ 1002
- Android 框架简介
- 湖南师大acm problem 10384 计算点到线段之间的距离
- POSIX的线程的取消点(Cancellation Point)的概念和实现方式
- google各国域名
- 黑马程序员-TCP传输数据
- u880刷2.3.7
- XMLHttpRequest类成员和实例
- JS 获得网页代码 远程网页源代码读取