十分机智,由于n太大,一般的网络流估计过不了,(然而加了读入优化当前弧优化的代码,上午T掉了,下午A了。。。还是错的模板,反边的流量操作搞成+了。。。)所以因为m只有10,所以对于每个人来说,能适应这些星球的情况最多2^11-1种,于是就可以统计出每种情况的人数,然后把每种情况建个点,有多少人是这种情况,就从源点连多少流量的边到这个点,然后再根据情况连无穷大的边到星球点,最后从星球点连边到汇点,控制每个星球的最多人数,事实上之前的时候1975ms,用这个正解只优化到了1400+ms,233.
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxl 100010
#define maxnode 2100
#define inf 2000000001
using namespace std;
int n,m,cnt,S,T,ans;
int a[maxl],sum[maxnode],ehead[maxnode],dis[maxnode],cur[maxnode];
struct node{int nxt,w,to;} e[maxnode*maxnode*2];
bool in[maxnode];
void add(int u,int v,int w)
{
e[++cnt].to=v;e[cnt].nxt=ehead[u];e[cnt].w=w;ehead[u]=cnt;
e[++cnt].to=u;e[cnt].nxt=ehead[v];e[cnt].w=0;ehead[v]=cnt;
}
inline int read()
{
int x=0;char ch=getchar();
while(ch<'0' || ch>'9') ch=getchar();
while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
return x;
}
void prework()
{
int d,t;
memset(ehead,0,sizeof(ehead));
memset(sum,0,sizeof(sum));
cnt=0;S=0,T=(1<<m)-1+m+1;
for(int i=1;i<=n;i++)
{
d=0;
for(int j=1;j<=m;j++)
{
scanf("%d",&t);
if(t)
d|=1<<(j-1);
}
sum[d]++;
}
for(int i=1;i<=(1<<m)-1;i++)
if(sum[i]>0)
{
add(S,i,sum[i]);
for(int j=1;j<=m;j++)
if(i&(1<<(j-1)))
add(i,(1<<m)-1+j,inf);
}
for(int i=1;i<=m;i++)
scanf("%d",&a[i]);
for(int i=1;i<=m;i++)
add((1<<m)-1+i,T,a[i]);
}
int max(int a,int b)
{
if(a>b)
return a;
else
return b;
}
int min(int a,int b)
{
if(a<b)
return a;
else
return b;
}
bool bfs()
{
int head=0,tail=1,u,v;
for(int i=S;i<=T;i++)
dis[i]=-1;
dis[S]=0;a[1]=S;
while(head!=tail)
{
head=(head+1)%maxl;
u=a[head];
for(int i=ehead[u];i;i=e[i].nxt)
if(e[i].w>0 && dis[e[i].to]<0)
{
dis[e[i].to]=dis[u]+1;
tail=(tail+1)%maxl;
a[tail]=e[i].to;
}
}
if(dis[T]<0)
return false;
else
return true;
}
int find(int u,int low)
{
int t,v;
if(u==T)
return low;
for(int &i=cur[u];i;i=e[i].nxt)
{
v=e[i].to;
if(dis[v]==dis[u]+1 && e[i].w>0 &&
(t=find(v,min(e[i].w,low))))
{
e[i].w-=t;
if(i&1)
e[i+1].w+=t;
else
e[i-1].w-=t;
return t;
}
}
return 0;
}
void mainwork()
{
int t;ans=0;
while(bfs())
{
for(int i=S;i<=T;i++)
cur[i]=ehead[i];
while((t=find(0,inf)))
ans+=t;
}
}
void print()
{
if(ans==n)
printf("YES\n");
else
printf("NO\n");
}
int main()
{
while(~scanf("%d%d",&n,&m))
{
prework();
mainwork();
print();
}
return 0;
}