【DP】UVA 10651 Pebble Solitaire 记忆化搜索
2014-09-03 16:16
399 查看
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <string> #include <iostream> #include <algorithm> using namespace std; #include <queue> #include <stack> #include <vector> #include <deque> #include <set> #include <map> #define cler(arr, val) memset(arr, val, sizeof(arr)) #define IN freopen ("in.txt" , "r" , stdin); #define OUT freopen ("out.txt" , "w" , stdout); typedef long long LL; const int MAXN = 111;//点数的最大值 const int MAXM = 20006;//边数的最大值 const int INF = 11521204; const int mod=1000000007; int dp[1<<14]; void print(int x) { int out=0; while(x) { int a=x%2; if(a) out++; x/=2; } printf("%d\n",out); } int bfs(int x) { queue<int>q; q.push(x); while(!q.empty()) { x=q.front(); q.pop(); for(int i=0; i<12; i++) { if((1 << i) & x) { if(i<10&&(x&(1<<(i+1)))&&!(x&(1<<(i+2)))) { int ans=x^(1<<(i+1)); ans=ans^(1<<(i+2)); ans=ans^(1<<i); if(!dp[ans]) { dp[ans]=1; q.push(ans); } } if(i>2&&(x&(1<<(i-1)))&&!(x&(1<<(i-2)))) { int ans=x^(1<<(i-1)); ans=ans^(1<<(i-2)); ans=ans^(1<<i); if(!dp[ans]) { dp[ans]=1; q.push(ans); } } } } } print(x); } int main() { char s[13]; int t; // IN; scanf("%d",&t); while(t--) { cler(dp,0); scanf("%s",s); int in=0,x=1; for(int i=0; i<12; i++) { in+=x*(s[i]=='o'?1:0); x*=2; } bfs(in); } return 0; }
相关文章推荐
- 【DP】UVA 10651 Pebble Solitaire 记忆化搜索
- uva 10651- Pebble Solitaire(状态压缩DP)待看。。。
- UVA 10651 Pebble Solitaire 状态压缩dp
- UVa 10651 Pebble Solitaire (DP 卵石游戏 记忆化搜索)
- UVa 10651 Pebble Solitaire (DP&bitset)
- UVa 10651 Pebble Solitaire(状压DP)
- UVa 10651 Pebble Solitaire(状态压缩DP)
- uva_10651_Pebble Solitaire(状态压缩DP)
- UVa 10651 Pebble Solitaire(状态压缩DP)
- UVa 10651 - Pebble Solitaire 状态压缩 dp
- [集合DP] UVA 10651 Pebble Solitaire
- UVA 10651 Pebble Solitaire 状压Dp
- UVa 10651 - Pebble Solitaire 状态压缩 dp
- UVa 10651 Pebble Solitaire(DP 记忆化搜索)
- UVa 10651 Pebble Solitaire(DP 记忆化搜索)
- UVa 10651 Pebble Solitaire(状态压缩DP)
- uva 10651 Pebble Solitaire(dp,状态压缩,记忆化搜索)
- UVA 10651 Pebble Solitaire 状态压缩dp
- 【UVA】10651-Pebble Solitaire(直接递归或者记忆化)
- UVA 10651 Pebble Solitaire(记忆化)