本题枚举每次可行的方案,并对枚举的上限做了限制,即如果当前的枚举次数已经大于目前最小次数解就剪枝。
/***********************************************
* Author: fisty
* Created Time: 2015/2/6 17:29:18
* File Name : 1_H.cpp
*********************************************** */
#include <iostream>
#include <cstring>
#include <deque>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <cstdio>
#include <bitset>
#include <algorithm>
using namespace std;
#define Debug(x) cout << #x << " " << x <<endl
#define Memset(x, a) memset(x, a, sizeof(x))
const int INF = 0x3f3f3f3f;
typedef long long LL;
typedef pair<int, int> P;
#define FOR(i, a, b) for(int i = a;i < b; i++)
#define MAX_N 1000
int deep, ok;
int A, B, C;
string ans[MAX_N], _ans[MAX_N];
int vis[110][110];
void dfs(int x, int y, int cnt){
if(deep < cnt) return ;
if(x == C || y == C){
if(cnt < deep) {
deep = cnt;
FOR(i, 0, deep) _ans[i] = ans[i];
ok = 1;
}
return ;
}
if(x < A && !vis[A][y]){
vis[A][y] = 1;
ans[cnt] = "FILL(1)";
dfs(A, y, cnt+1);
vis[A][y] = 0;
}
if(y < B && !vis[x][B]){
vis[x][B] = 1;
ans[cnt] = "FILL(2)";
dfs(x, B, cnt+1);
vis[x][B] = 0;
}
if(x > 0 && !vis[0][y]){
vis[0][y] = 1;
ans[cnt] = "DROP(1)";
dfs(0, y, cnt+1);
vis[0][y] = 0;
}
if(y > 0 && !vis[x][0]){
vis[x][0] = 1;
ans[cnt] = "DROP(2)";
dfs(x, 0, cnt+1);
vis[x][0] = 0;
}
if(x > 0 && y < B){
int t = min(x, B-y);
if(!vis[x-t][y+t]){
vis[x-t][y+t] = 1;
ans[cnt] = "POUR(1,2)";
dfs(x-t, y+t, cnt+1);
vis[x-t][y+t] = 0;
}
}
if(y > 0 && x < A){
int t = min(y, A-x);
if(!vis[x+t][y-t]){
vis[x+t][y-t] = 1;
ans[cnt] = "POUR(2,1)";
dfs(x+t, y-t, cnt+1);
vis[x+t][y-t] = 0;
}
}
return ;
}
int main() {
//freopen("in.cpp", "r", stdin);
cin.tie(0);
ios::sync_with_stdio(false);
cin >> A >> B >> C;
deep = INF; ok = 0;
Memset(vis, 0);
vis[0][0] = 1;
dfs(0, 0, 0);
if(ok){
cout << deep << endl;
FOR(i, 0, deep) cout << _ans[i] << endl;
}else{
cout << "impossible" << endl;
}
return 0;
}