USACO6.5.5 Checker Challenge( checker)
2015-02-06 19:51
218 查看
USACO最后一题,八皇后的类似问题,dfs加优化就可以轻松过了
/* ID:xsy97051 TASK:checker LANG:C++ */ #include <iostream> #include <fstream> int n, aim, ans; int a[20]; void dfs(int row, int ld, int rd, int i) { int p, pos; if(row!=aim) { pos=aim&(~(row|ld|rd)); while(pos!=0) { p=pos&(pos^(pos-1)); pos-=p; if(ans<3) { int l=1, k=p; while(k!=1) { k=k>>1; l++; } a[i]=l; } dfs(row|p,(ld|p)<<1,(rd|p)>>1,i+1); } } else { ans++; if(ans<=3) { cout<<a[1]; for(int k=2; k<=n; k++) cout<<" "<<a[k]; cout<<endl; } } } int main() { freopen("checker.in","r",stdin); freopen("checker.out","w",stdout); cin>>n; aim=(1<<n)-1; dfs(0,0,0,1); cout<<ans<<endl; return 0; }
相关文章推荐
- usaco6.5.5 Checker Challenge
- USACO 6.5.5 Checker Challenge 回溯
- usaco Checker Challenge
- USACO section 1.5 Checker Challenge(dfs深搜)
- USACO-cha1-sec1.5 Checker Challenge
- USACO Section 1.5 Checker Challenge - 普普通通的皇后问题~~
- USACO 1.5 Checker Challenge (DFS)
- USACO 1.5 Checker Challenge (checker)
- USACO 1.5 Checker Challenge (DFS + 剪枝)
- USACO 1.5 Checker Challenge(DFS)
- USACO 1.5.4 Checker Challenge ———— DFS
- USACO 1.5 Checker Challenge
- [USACO 1.5.4] Checker Challenge
- USACO 1.5 Checker Challenge (位操作)
- USACOTrainning.Checker Challenge
- USACO1.5.4 checker challenge
- USACO 1.5 Checker Challenge
- [usaco]1.5 Checker Challenge
- USACO 1.5.4 Checker Challenge
- There are 常数s 和 常数s! Usaco 1.5.4 Checker Challenge