fork download
  1. #include<stdio.h>
  2. #include<stdbool.h>
  3. bool use(int u[3][3], int a, int b, int c){
  4. if(a < 0|| b < 0|| c < 0) return false;
  5. if(a + b + c == 0) return true;
  6. return use(u, a - u[0][0], b - u[0][1], c - u[0][2])|use(u, a - u[1][0], b - u[1][1], c - u[1][2])|use(u, a - u[2][0], b - u[2][1], c - u[2][2]);
  7. return false;
  8. }
  9.  
  10. void check(int u[3][3], int n){
  11. if(n<=0) return;
  12. int a, b, c;
  13. scanf("%d %d %d", &a, &b, &c);
  14. if(use(u, a, b, c)) printf("yes\n");
  15. else printf("no\n");
  16. check(u, n-1);
  17. }
  18.  
  19. int main(){
  20. int u[3][3];
  21. scanf("%d %d %d %d %d %d %d %d %d", &u[0][0], &u[0][1], &u[0][2], &u[1][0], &u[1][1], &u[1][2], &u[2][0], &u[2][1], &u[2][2]);
  22. int n;
  23. scanf("%d", &n);
  24. check(u, n);
  25. }
Success #stdin #stdout 0.01s 5280KB
stdin
1 1 2
2 3 1
1 2 4
5
1 1 1
1 1 2
6 8 6
10 10 10
4 6 7
stdout
no
yes
yes
no
yes