# UVALive 4794 Sharing Chocolate

#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <utility>
using namespace std;

#define rep(i,j,k) for (int i=j;i<=k;i++)
#define Rrep(i,j,k) for (int i=j;i>=k;i--)

#define Clean(x,y) memset(x,y,sizeof(x))
#define LL long long
#define ULL unsigned long long
#define inf 0x7fffffff
#define mod 100000007
const int maxn = 1<<15;
int n,uplim;
int X,Y;
int a[20];
int sum[maxn+10]; //∑s
bool vis[101][maxn+10];
bool dp[101][maxn+10];
int num[maxn+10];

void init()
{
cin>>X>>Y;
rep(i,1,n)
scanf("%d",&a[i]);
uplim = (1<<n)-1;
rep(i,0,uplim)
{
num[i] = 0;
sum[i] = 0;
rep(j,0,n-1)
if ( i & (1<<j) ) sum[i] += a[j+1],num[i]++;
}
Clean(vis,false);
}

bool dfs( int Lx , int state )
{
if ( vis[Lx][state] ) return dp[Lx][state];
if ( num[state] == 1 ) return true;
vis[Lx][state] = true;
int Ly = sum[state] / Lx;
bool &ans = dp[Lx][state];
ans = false;
for ( int i = (state - 1) & state; i; i = (i - 1) & state )
{
if ( sum[i] % Lx == 0 && sum[state^i] % Lx == 0 )
ans |= dfs( min( Lx , sum[i]/Lx ) , i ) & dfs( min( Lx , sum[state^i]/Lx ) , state^i );
if ( sum[i] % Ly == 0 && sum[state^i] % Ly == 0 )
ans |= dfs( min( Ly , sum[i]/Ly ) , i ) & dfs( min( Ly , sum[state^i]/Ly ) , state^i );
if ( ans ) return true;
}
return ans;
}

bool solve()
{
if ( sum[uplim] != X * Y || sum[uplim] % X ) return false;
return dfs( min(X,Y) , uplim );
}

int main()
{
int kase = 0;
while( cin>>n )
{
if ( !n ) break;
init();
printf("Case %d: %s\n",++kase,solve()?"Yes":"No");
}
return 0;
}


#### UVAlive - 4794—— Sharing Chocolate

2016-05-18 21:35:42

#### UVALive - 4794 Sharing Chocolate DP

2015-02-27 10:12:45

#### Sharing Chocolate UVALive - 4794（动态规划）

2018-03-21 20:59:17

#### UVA 1099 - Sharing Chocolate(记忆化搜索+状态压缩)

2014-02-16 14:13:36

#### LA 4794 Sharing Chocolate .

2016-10-23 16:15:29

#### LA 4794 Sharing Chocolate

2016-04-23 14:53:07

#### 【暑假】[深入动态规划]UVAlive 4794 Sharing Chocolate

2016-03-30 17:20:52

#### uva 1099 - Sharing Chocolate(记忆化搜索）

2014-02-18 10:07:51

#### LA 4794(Sharing Chocolate-记忆化搜索)

2015-12-08 11:34:32

#### LA - 4794 - Sharing Chocolate（状态压缩dp）

2013-04-16 21:42:34