#include #include int **s; int h, w, n, k; int s_count; int p_count = 1; int check(int a, int b); void set(int a, int b, int c); void count(); int main(void){ int i, j; scanf("%d %d %d %d", &h, &w, &n, &k); s_count = h * w; s = malloc(sizeof(double *) * h); for(i = 0; i < h; i++){ s[i] = malloc(sizeof(double *) * w); } for(i = 0; i < h; i++){ for(j = 0; j < w; j++){ s[i][j] = 0; } } for(i = 0; i < h; i++){ for(j = 0; j < w; j++){ if(s[i][j] == 0){ set(i, j, check(i, j)); } } } for(i = 0; i < h; i++) free(s[i]); free(s); return 0; } int check(int a, int b){ int sum = 0; int i, j; for(i = 0; i < h; i++){ if(s[i][b] == 0) sum += 1; } if(sum == s_count){ sum = 0; for(i = 0; i < w; i++){ if(s[a][i] == 0) sum += 1; } if(sum == s_count) return 0; else return 1; } else return 2; } void set(int a, int b, int c){ int i; switch(c){ case 0: if(p_count == k) printf("YES\n"); else printf("NO\n"); break; case 1: for(i = 0; i < w; i++){ if(s[a][i] == 0){ s[a][i] = 1; s_count--; } } count(); break; case 2: for(i = 0; i < h; i++){ if(s[i][b] == 0){ s[i][b] = 1; s_count--; } } count(); break; } } void count(){ p_count++; if(p_count == n + 1) p_count = 1; }