提交时间:2021-06-24 13:23:12

运行 ID: 20956

#include <bits/stdc++.h> using namespace std; int ans=0; int n,k; bool 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]==0||need[j]==2)need[j]=2; else { cout<<-1; exit(0); } } if(a==1) { if(need[j]==0||need[j]==1)need[j]=1; 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; }