提交时间:2021-06-24 13:40:01
运行 ID: 20958
#include <bits/stdc++.h> using namespace std; int ans=0; int n,k; int need[20]; bool food[20]; void dfs(int deep) { if(deep>=k) { //for(int i=1; i<=deep; i++)cout<<food[i]<<' '; //cout<<endl; bool can=true; for(int i=1; i<=k; i++) if((food[i]&&need[i]==2)|| !food[i]&&need[i]==1)can=false; if(can)ans++; } else { food[deep+1]=0; dfs(deep+1); food[deep+1]=1; dfs(deep+1); } } int main() { cin>>n>>k; for(int i=1; i<=n; i++) { for(int j=1; j<=k; j++) { int a; cin>>a; if(a==2) { if(need[j]!=1)need[j]=a; else { cout<<-1; exit(0); } } if(a==1) { if(need[j]!=2)need[j]=a; else { cout<<-1; exit(0); } } } } //for(int i=1; i<=k; i++)cout<<need[i]<<' '; //cout<<endl; dfs(0); if(ans)cout<<ans; else cout<<-1; }