Service Center

来源:互联网 发布:宿舍用品淘宝店 编辑:程序博客网 时间:2024/05/18 03:07

Electronics Service Center was visited by a total of N customers

Service Center has a total of M employees.

To those employees that customers visit in order to get in line, line stands, if the services of no n-employee immediately to receive services.

Customers get tickets which are labeled from 1 to N by service center and return the tickets when their service is finished.

Write a program to check if the sequence of tickets is possible after finishing service for all customers.

For example, if the number of customers (N) is 5, the number of total employees (M) is 3,

1-2-3-4-5, 1-3-5-2-4, 3-4-1-5-2 is possible, whereas 4-1-2-3-5, 3-5-4-2-1 is impossible.


[Input]


There can be more than one test case in the input.

The first line has T, the number of test cases.

Then the totally T test cases are provided in the following lines.

In each test case, the first line has three integer; the number of customers (N), the number of employees (M), the number of sequence(S) to be verified.

For next S lines, each contains the sequence of retuning tickets.


[Output]


For each test case, you should print your answer in one line.

Print “1” if the sequence is possible or “0” if the sequence is impossible.


[Input Example]


2

5 3 5
1 2 3 4 5

1 3 5 2 4

3 4 1 5 2

4 1 2 3 5

3 5 4 2 1

5 5 3

3 4 1 5 2

4 1 2 3 5

3 5 4 2 1


[Output Example]


11100

111


#include <stdio.h>int N, M, P;int data[11][1001];int answer[11][11];int main(void) {int test_case;int T;setbuf(stdout, NULL);scanf("%d", &T);for (test_case = 0; test_case < T; test_case++) {int i, j;scanf("%d %d %d", &N, &M, &P);for (i = 1; i <= P; i++) {for (j = 1; j <= N; j++) {scanf("%d", &data[i][j]);}}for (i = 1; i <= P; i++) {answer[test_case][i] = 1;  //set value 1 instead of 0}for (i = 1; i <= P; i++) {int maxCustomerN = M;for (j = 1; j <= N; j++) {if (data[i][j] > maxCustomerN) {answer[test_case][i] = 0;break;}maxCustomerN++;}}// Print the answer to standard output(screen).for (i = 1; i <= P; i++) {printf("%d", answer[test_case][i]);}printf("\n");}return 0; //Your program should return 0 on normal termination.}