jakaria_hossain

lightoj - 1261 - K-SAT Problem

Aug 23rd, 2019
257
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. double const EPS=1e-6;
  5. using namespace std;
  6. const int N = 35;
  7.  
  8. int inp[N][N], n, m, k, ans[N], p;
  9. void input()
  10. {
  11. cin >> n >> m >> k;
  12. int i, j ;
  13.  
  14. for ( i = 0 ; i < n ; i++ )
  15. {
  16. for ( j = 0 ; j < k ; j++ ) cin >> inp[i][j];
  17. }
  18. cin >> p ;
  19. for ( i = 0 ; i < p ; i++ ) cin>> ans[i];
  20.  
  21. }
  22. bool solve()
  23. {
  24. int i, j, x;
  25. for ( i = 0 ; i < n ; i++ )
  26. {
  27. bool ok = false ;
  28. for ( j = 0 ; j < k && !ok ; j++ )
  29. {
  30. int wish = inp[i][j];
  31. // printf ( " Person :: %d wish :: %d\n", i , wish );
  32. bool nai = true ;
  33. bool ase = false;
  34. for ( x = 0 ; x < p ; x++ )
  35. {
  36. if ( abs(wish) == ans[x] )
  37. {
  38. nai = false;
  39. ase = true;
  40. }
  41. }
  42.  
  43. if ( wish < 0 && nai ) ok = true;
  44. if ( wish > 0 && ase ) ok = true;
  45. }
  46. if ( ok == false ) return 0;
  47.  
  48. }
  49. return 1;
  50.  
  51. }
  52.  
  53. int main()
  54. {
  55. int cs, t;
  56. scanf("%d",&t);
  57. for ( cs = 1 ;cs <= t ; cs++ )
  58. { input();
  59. printf("Case %d: %s\n",cs,solve()?"Yes":"No");
  60.  
  61. }
  62.  
  63.  
  64. return 0;
  65. }
RAW Paste Data