Pku 3490
显然?!。。棋盘上的棋子可以按照横纵坐标mod 3的余数分为9种。。然后跳两格的操作等价于拿走两种棋子然后放入一种新棋子。所以记忆化搜索暴力上个map。。然而棋盘不一定允许这种操作,所以预处理可行的交换。。(一开始只枚举给出的10个棋子,然后出错了。。。)然后判断类型的时候3*(x%3)一定要加括号。。。
总的可能性有C(18,8) < 50000 种
然后对于这个计算。。
等价于有9个篮子要往里面放10个苹果,允许篮子放空,但苹果一定要放完的方案数
先考虑没有篮子放空的情况:
10个苹果有9个空隙,只要放8个隔板就能分出9类C(9,8)
然后等价于
x1 + x2 + x3 + ... + x9 = 10
xi > 0
对于原问题
(x1+1) + (x2+1) + (x3+1) + ... + (x9+1) = 19
xi+1>0
就是18个空隙放8个隔板 C(18,8)
#include<iostream> #include<cstdio> #include<cstdlib> #include<algorithm> #include<cstring> #include<cmath> #include<vector> #include<queue> #include<map> using namespace std; typedef long long LL; const int dx[8] = {0,1,0,-1,1,-1,1,-1}; const int dy[8] = {1,0,-1,0,1,-1,-1,1}; const int ch[9][9] = {{0,2,1,6,8,7,3,5,4},{2,1,0,8,7,6,5,4,3},{1,0,2,7,6,8,4,3,5}, {6,8,7,3,5,4,0,2,1},{8,7,6,5,4,3,2,1,0},{7,6,8,4,3,5,1,0,2}, {3,5,4,0,2,1,6,8,7},{5,4,3,2,1,0,8,7,6},{4,3,5,1,0,2,7,6,8}}; map <LL,int> ma; int n,m,k,X,Y,p[10][10],x[10],y[10]; LL now,goal,fac[10],che[10]; int ABS(int x) {return x < 0?-x:x;} void Add(int X1,int Y1,int X2,int Y2) { int A = 3*(X1%3) + Y1%3; int B = 3*(X2%3) + Y2%3; p[A][B] = p[B][A] = 1; } void Work(int a,int b) { for (int l = 0; l < 8; l++) { int xa = a + dx[l]*3; int yb = b + dy[l]*3; if (xa < 1 || xa > n || yb < 1 || yb > m) continue; for (int i = 0; i < 8; i++) { int xx = xa + dx[i]; int yy = yb + dy[i]; if (xx < 1 || xx > n || yy < 1 || yy > m) continue; Add(a,b,xx,yy); } } for (int i = 0; i < 8; i++) { int xx = a + dx[i]; int yy = b + dy[i]; if (xx < 1 || xx > n || yy < 1 || yy > m) continue; Add(a,b,xx,yy); } } bool dfs(LL now,int tot) { if (now == goal) return 1; if (ma[now]) return 0; else ma[now] = 1; if (tot == 1) return 0; for (int i = 0; i < 9; i++) for (int j = i + 1; j < 9; j++) if (p[i][j] && che[i] && che[j]) { --che[i]; --che[j]; ++che[ch[i][j]]; LL nex = 0; for (int l = 0; l < 9; l++) nex += fac[l]*che[l]; if (dfs(nex,tot-1)) return 1; ++che[i]; ++che[j]; --che[ch[i][j]]; } return 0; } int main() { #ifdef YZY freopen("galaxy4.in","r",stdin); #endif fac[0] = 1; for (int i = 1; i < 10; i++) fac[i] = fac[i-1]*11LL; while (scanf("%d%d%d%d%d",&k,&n,&m,&X,&Y) != EOF) { memset(p,0,sizeof(p)); memset(che,0,sizeof(che)); ma.clear(); goal = fac[3*(X%3) + Y%3]; for (int i = 0; i < k; i++) { scanf("%d%d",&x[i],&y[i]); ++che[3*(x[i]%3) + y[i]%3]; } for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) Work(i,j); LL st = 0; for (int i = 0; i < 9; i++) st += che[i]*fac[i]; if (dfs(st,k)) printf("Yes\n"); else printf("No\n"); } return 0; }