hdu 1045 Fire Net
2012-04-01 23:24
357 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1045 暴力搜索
View Code
View Code
#include<iostream> #include<cstring> #include<cstdlib> #include<cstdio> using namespace std; char mat[10][10]; int n,maxx; bool ok(int x,int y)//put here is ok { if(mat[x][y]!='.') return false; int i,j; for(i=x-1;i>=0;i--) { if(mat[i][y]=='X') break; else if(mat[i][y]=='O') return false; } for(j=y-1;j>=0;j--) { if(mat[x][j]=='X') break; else if(mat[x][j]=='O') return false; } return true; } void search(int pos,int num)//自左向右,自上而下 { if(pos==n*n)// { if(maxx<num) maxx=num; return; } int x=pos/n; int y=pos%n; if(ok(x,y)) { mat[x][y]='O'; search(pos+1,num+1); mat[x][y]='.'; } search(pos+1,num); } int main() { int i,j; while(cin>>n && n) { for(i=0;i<n;i++) for(j=0;j<n;j++) cin>>mat[i][j]; maxx=-1; search(0,0); cout<<maxx<<endl; } return 0; }
相关文章推荐
- hdu 1045 Fire Net-dfs
- HDU_1045 Fire Net
- HDU 1045 - Fire Net
- HDU1045 Fire Net
- hdu 1045 Fire Net 二分行列匹配
- HDU 1045 Fire Net dfs
- hdu 1045 Fire Net 二分匹配
- HDU 1045 Fire Net 详细题解(二分图经典模型)
- HDU 1045 Fire Net
- HDU-1045 Fire Net
- HDU 1045 Fire Net
- hdu 1045 Fire Net
- hdu 1045 Fire Net&二分图解法
- hdu 1045 Fire Net
- [面试备] 暴搜 or 二分图的经典升级 : hdu 1045 Fire Net 示例 [ 讲解之用 ]
- 【最大独立集 && 有墙 && 无向图】HDU - 1045 Fire Net
- HDU 1045 Fire Net
- [面试备] 暴搜 or 二分图的经典升级 : hdu 1045 Fire Net 示例 [ 讲解之用 ]
- [面试备] 暴搜 or 二分图的经典升级 : hdu 1045 Fire Net 示例 [ 二分图 ]
- hdu 1045 Fire Net