pat甲级1051

#include 
#include
#include
using namespace std;
vectorv;
int m, n, k;
bool isok() {
	vectortest;
	int maxnum = 0;//入过栈的最大值
	for (int i = 0; i < n; i++) {
		if (test.size() == 0||maxnum < v[i]){
			for (int j = maxnum+1; j <= v[i];j++) {
				test.push_back(j);
			}
			if (test.size() > m)
				return false;
			maxnum = v[i];
		}
		if (test.back() == v[i])
			test.pop_back();
		else
			return false;
	}
	return true;
}
int main() {
	scanf("%d%d%d", &m, &n, &k);
	for (int i = 0; i < k; i++) {
		v.clear();//clear之后大小会变吗,会变成0
		for (int j = 0; j < n; j++) {
			int num;
			scanf("%d", &num);
			v.push_back(num);
		}		
		isok()?printf("YES\n"):printf("NO\n");
	}
	return 0;
}

 

你可能感兴趣的:(pat甲级1051)