fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. int l, dp[1004][1004], mn = 100000, i, j;
  5.  
  6. vector<int>v[110];
  7. string s[110];
  8.  
  9. void rec(int pos, set<int>st, int cnt)
  10. {
  11. if(st.size() == 4){
  12. mn = min(mn, cnt);
  13. return;
  14. }
  15.  
  16. rec(pos+1, st, cnt);
  17. for(auto a: v[pos]){
  18. st.insert(a);
  19. }
  20. rec(pos+1, st, cnt+1);
  21. }
  22. int main()
  23. {
  24. int t, cs=1, n, m;
  25. cin>>t;
  26.  
  27. for(int tc = 1; tc <= t; tc++){
  28. cin>>n;
  29.  
  30. for(i = 0; i < n; i++){
  31. cin>>s[i];
  32. }
  33. m = s[0].size();
  34.  
  35. for(i = 0; i < m; i++){
  36. for(j = 0; j < n; j++){
  37. if(s[i][j] == 'Y')
  38. v[i].push_back(j);
  39. }
  40. }
  41. set<int>st;
  42. rec(0, st, 0);
  43. for(auto a: v[0]){
  44. st.insert(a);
  45. }
  46. rec(0, st, 1);
  47. cout<<"Case "<<tc<<": "<<mn<<endl;
  48. mn = 100000;
  49. for(i = 0; i < m; i++)
  50. v[i].clear();
  51. }
  52. }
  53.  
Internal error #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty