目要求只能横着切和纵着切,而且必须一次切到底,所以每次切割的巧克力只能是矩形,设l w分别为举行的的宽和长,S表示要把巧克力切割成块的集合,sum[S]表示其面积的和,只有l*w == sum[S]的状态才是有可能切割成功的,所以可以定义状态table[l][S]表示宽为l的矩形切割成状态为S的块是否可以成功,因为S和l确定了,w也就确定了,其中 w = sum[S]/l , table[l][S] = ∑(table[min(l, sum[S0]/l)][S0]&&table[min(l, sum[S0]/l)][S-S0] || table[min(w, sum[S0]/w)][S0]&&table[min(w, sum[S0]/w)][S-S0])∑为逻辑加
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <cctype>
#include <utility>
#include <map>
#include <string>
#include <climits>
#include <set>
#include <string>
#include <sstream>
#include <utility>
#include <ctime>
//#pragma comment(linker, "/STACK:1024000000,1024000000")
using std::priority_queue;
using std::vector;
using std::swap;
using std::stack;
using std::sort;
using std::max;
using std::min;
using std::pair;
using std::map;
using std::string;
using std::cin;
using std::cout;
using std::set;
using std::queue;
using std::string;
using std::istringstream;
using std::getline;
using std::make_pair;
using std::greater;
const int MAXN(15);
int table[110][(1 << MAXN)+10];
int sum[(1 << MAXN)+10];
int dfs(int l, int S)
{
if(table[l][S] != -1)
return table[l][S];
int &cur = table[l][S];
if((S^(S&(-S))) == 0)
return cur = 1;
int w = sum[S]/l;
for(int S0 = (S-1)&S; S0; S0 = (S0-1)&S)
{
int S1 = S0^S;
if(sum[S0]%l == 0 && dfs(min(l, sum[S0]/l), S0) && dfs(min(l, sum[S1]/l), S1))
return cur = 1;
if(sum[S0]%w == 0 && dfs(min(w, sum[S0]/w), S0) && dfs(min(w, sum[S1]/w), S1))
return cur = 1;
}
return cur = 0;
}
int main()
{
int N, n_case(0);
int x, y;
while(scanf("%d", &N), N)
{
scanf("%d%d", &x, &y);
for(int i = 0; i < N; ++i)
{
int temp;
scanf("%d", &temp);
sum[1 << i] = temp;
}
int limit = (1 << N)-1;
for(int i = 1; i <= limit; ++i)
{
sum[i] = sum[i^(i&(-i))]+sum[i&(-i)];
}
int ans = 0;
if(sum[limit] == x*y)
{
memset(table, -1, sizeof(table));
ans = dfs(min(x, y), limit);
}
printf("Case %d: %s\n", ++n_case, ans? "Yes": "No");
}
return 0;
}