Service Center

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.
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值