/*
状态搜索,BFS。。
*/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<queue>
#define manx 18
using namespace std;
struct node{ / 记录某状态
int mp[8][manx]; 大州
int temp;
}ant[2];
int a[manx],b[manx],pos[manx],ans,sum;
int n,m,k;
queue<node>que;
void judge(node te,int a,int b,int c){帮助 a 元素
int h1=pos[a];
int h2=pos[b];
int h3=pos[c];
te.mp[h1][a]-=2;
if(te.mp[h1][a]<1) te.mp[h1][a]=1;
te.mp[h2][b]+=2;
if(te.mp[h2][b]>5) return ;
te.mp[h3][c]+=2;
if(te.mp[h3][c]>5) return ;
for(int i=0;i<n;i++){
if(te.mp[h2][i] && i!=b){
te.mp[h2][i]+=1;
if(te.mp[h2][i]>5) return ;
}
if(te.mp[h3][i] && i!=c){
te.mp[h3][i]+=1;
if(te.mp[h3][i]>5) return ;
}
}
te.temp++;
que.push(te);
return ;
}
void fan(){
int z[4];
for(int i=0;i<3;i++)
scanf("%d",&z[i]);
while(!que.empty()){
node te=que.front();
if(sum<te.temp) { sum=te.temp; break; } /这里有猫腻额
que.pop();
node p=te;
judge(p,z[0],z[1],z[2]);///z[0]要帮助的
judge(p,z[1],z[0],z[2]);///z[1]
judge(p,z[2],z[0],z[1]);///z[2]
}
}
int main(){
int t;
scanf("%d",&t);
for(int ca=1;ca<=t;ca++){
ans=0; sum=0;
scanf("%d%d%d",&n,&m,&k);
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
}
for(int i=0;i<n;i++){
scanf("%d",&b[i]);
}
while(!que.empty()) que.pop();
memset(ant,0,sizeof(ant));
for(int i=0;i<n;i++){
ant[ans].mp[a[i]][i]=b[i]; ///第a[i]个大洲 第 i 个位置
pos[i]=a[i];
}
que.push(ant[ans]);
for(int i=0;i<k;i++)
fan();
printf("Case #%d: %d\n",ca,sum);
}
}
/*
6
9 3 2
0 0 0 1 1 1 2 2 2
5 3 3 3 3 3 3 3 3
0 3 6
0 3 6
*/
HDU 4536 状态搜索
最新推荐文章于 2016-07-12 16:48:25 发布