Guest User

Untitled

a guest
Aug 26th, 2018
658
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.84 KB | None | 0 0
  1. /*
  2. ID: hepic
  3. PROG: sabotage
  4. LANG: C++11
  5. */
  6. #include <bits/stdc++.h>
  7.  
  8. #define FOR(i, a, b) for(auto i=a; i<=b; ++i)
  9. #define REP(i, a, b) for(auto i=a; i<b; ++i)
  10. #define FORI(i, a, b) for(auto i=a; i!=b+1-2*(a>b); i+=1-2*(a>b))
  11. #define REPI(i, a, b) for(auto i=a-(a>b); i!=b-(a>b); i+=1-2*(a>b))
  12. #define ALL(v) v.begin(),v.end()
  13. #define mp(a, b) make_pair(a, b)
  14. #define pb(a) push_back(a)
  15. #define pf(a) push_front(a)
  16. #define eb(a, b) emplace_back(a, b)
  17. #define fir first
  18. #define sec second
  19. #define what_is(x) cout<<#x<<" is "<<x<<endl;
  20. #define type(x) typeid(x).name()
  21. #define ms(arr, val) memset(arr, val, sizeof(arr))
  22. #define min3(a,b,c) min(min(a,b),c)
  23. #define max3(a,b,c) max(max(a,b),c)
  24. #define PI acos(-1)
  25. #define open_read1 freopen("a.txt", "r", stdin)
  26. #define open_write1 freopen("b.xt", "w", stdout)
  27. #define open_read freopen("sort.in", "r", stdin)
  28. #define open_write freopen("sort.out", "w", stdout)
  29.  
  30. using namespace std;
  31.  
  32. typedef long long LL;
  33. typedef long double LD;
  34. typedef unsigned long long ULL;
  35. typedef pair<double, double> PDD;
  36. typedef pair<int, int> PII;
  37. typedef pair<int, PII> PIPII;
  38. typedef pair<PII, PII> PPIIPII;
  39. typedef pair<LL, LL> PLL;
  40. typedef pair<ULL, ULL> PUU;
  41. typedef pair<LL, PLL> PLPLL;
  42. typedef pair<PLL, PLL> PPLLPLL;
  43. typedef pair<int, LL> PIL;
  44. typedef pair<LL, int> PLI;
  45.  
  46.  
  47. template<typename T, typename T1>
  48. ostream& operator << (ostream &out, pair<T, T1> obj)
  49. {
  50.     out << "(" << obj.first << ", " << obj.second << ")";
  51.     return out;
  52. }
  53.  
  54.  
  55. template<typename T, typename T1>
  56. ostream& operator << (ostream &out, map<T, T1> cont)
  57. {
  58.     typename map<T, T1>::const_iterator itr = cont.begin();
  59.     typename map<T, T1>::const_iterator ends = cont.end();
  60.  
  61.     for(; itr!=ends; ++itr)
  62.         out<<*itr<<" ";
  63.     out<<endl;
  64.  
  65.     return out;
  66. }
  67.  
  68.  
  69. template<typename T>
  70. ostream& operator << (ostream &out, set<T> cont)
  71. {
  72.     typename set<T>::const_iterator itr = cont.begin();
  73.     typename set<T>::const_iterator ends = cont.end();
  74.  
  75.     for(; itr!=ends; ++itr)
  76.         out<<*itr<<" ";
  77.     out<<endl;
  78.  
  79.     return out;
  80. }
  81.  
  82.  
  83. template<typename T>
  84. ostream& operator << (ostream &out, multiset<T> cont)
  85. {
  86.     typename multiset<T>::const_iterator itr = cont.begin();
  87.     typename multiset<T>::const_iterator ends = cont.end();
  88.  
  89.     for(; itr!=ends; ++itr)
  90.         out<<*itr<<" ";
  91.     out<<endl;
  92.  
  93.     return out;
  94. }
  95.  
  96.  
  97. template<typename T, template<typename ELEM, typename ALLOC=allocator<ELEM>> class CONT>
  98. ostream& operator << (ostream &out, CONT<T> cont)
  99. {
  100.     typename CONT<T>::const_iterator itr = cont.begin();
  101.     typename CONT<T>::const_iterator ends = cont.end();
  102.  
  103.     for(; itr!=ends; ++itr)
  104.         out<<*itr<<" ";
  105.     out<<endl;
  106.  
  107.     return out;
  108. }
  109.  
  110.  
  111. template<typename T, unsigned int N, typename CTy, typename CTr>
  112. typename enable_if<!is_same<T, char>::value, basic_ostream<CTy, CTr> &>::type
  113. operator << (basic_ostream<CTy, CTr> &out, const T (&arr)[N])
  114. {
  115.      REP(i, 0, N)
  116.         out<<arr[i]<<" ";
  117.     out<<endl;
  118.  
  119.     return out;
  120. }
  121.  
  122.  
  123. template<typename T>
  124. T gcd(T a, T b)
  125. {
  126.     T min_v = min(a, b);
  127.     T max_v = max(a, b);
  128.  
  129.     while(min_v)
  130.     {
  131.         T temp = max_v % min_v;
  132.         max_v = min_v;
  133.         min_v = temp;
  134.     }
  135.  
  136.     return max_v;
  137. }
  138.  
  139.  
  140. template<typename T>
  141. T lcm(T a, T b)
  142. {
  143.     return (a*b) / gcd(a, b);
  144. }
  145.  
  146.  
  147. template<typename T>
  148. T fast_exp_pow(T base, T exp, T mod)
  149. {
  150.     T res = 1;
  151.  
  152.     while(exp)
  153.     {
  154.         if(exp&1)
  155.         {
  156.             res *= base;
  157.             res %= mod;
  158.         }
  159.  
  160.         exp >>= 1;
  161.         base *= base;
  162.         base %= mod;
  163.     }
  164.  
  165.     return res % mod;
  166. }
  167.  
  168. /*#################################################################################################################
  169. #################################################################################################################
  170. ################################################################################################################
  171. #################################################################################################################*/
  172.  
  173. #define SIZE 110
  174.  
  175. int T, N, M, P;
  176. int one[SIZE], zero[SIZE];
  177. int dpWays[SIZE * SIZE][2];
  178. string pref[SIZE], forb[SIZE];
  179.  
  180.  
  181. void calculate() {
  182.     REP (i, 0, P) {
  183.         if (!i) {
  184.             ++dpWays[zero[i]][0];
  185.             ++dpWays[one[i]][0];
  186.             continue;
  187.         }
  188.        
  189.         for (int j = SIZE * SIZE - 1; j >= 0; --j) {
  190.             if (j - zero[i] >= 0) {
  191.                 dpWays[j][1] += dpWays[j - zero[i]][0];
  192.             }
  193.  
  194.             if (j - one[i] >= 0) {
  195.                 dpWays[j][1] += dpWays[j - one[i]][0];
  196.             }
  197.         }
  198.        
  199.         REP (j, 0, SIZE * SIZE) {
  200.             dpWays[j][0] = dpWays[j][1];
  201.             dpWays[j][1] = 0;
  202.         }
  203.     }
  204. }
  205.  
  206.  
  207. int main() {
  208.     scanf("%d", &T);
  209.  
  210.     FOR (t, 1, T) {
  211.         scanf("%d%d%d", &N, &M, &P);
  212.  
  213.         REP (i, 0, N) {
  214.             cin >> pref[i];
  215.         }
  216.  
  217.         REP (i, 0, M) {
  218.             cin >> forb[i];
  219.         }
  220.        
  221.         ms(zero, 0);
  222.         ms(one, 0);
  223.  
  224.         REP (i, 0, P) {
  225.             REP (j, 0, N) {
  226.                 if (pref[j][i] == '0') {
  227.                     ++zero[i];
  228.                 } else {
  229.                     ++one[i];
  230.                 }
  231.             }
  232.         }
  233.  
  234.         ms(dpWays, 0);
  235.         calculate();
  236.  
  237.         REP (i, 0, M) {
  238.             int cnt = 0;
  239.            
  240.             REP (j, 0, P) {
  241.                 if (forb[i][j] == '0') {
  242.                     cnt += one[j];
  243.                 } else {
  244.                     cnt += zero[j];
  245.                 }
  246.             }
  247.            
  248.             --dpWays[cnt][0];
  249.         }
  250.        
  251.         FOR (i, 0, N * P) {
  252.             if (dpWays[i][0] > 0) {
  253.                 printf("Case #%d: %d\n", t, i);
  254.                 break;
  255.             }
  256.         }
  257.     }
  258.  
  259.     return 0;
  260. }
Advertisement
Add Comment
Please, Sign In to add comment