Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

#沙發#记忆搜索,水題,咋没人做?

Posted by KatrineYang at 2016-11-16 13:51:32 on Problem 1530 and last updated at 2016-11-16 13:51:44
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <cstring>

using namespace std;

int slump[65][65], slimp[65][65];
int l;
char s[65];

void init(){
	scanf("%s", s);
	l = strlen(s);
	for(int i = 0; i <= l; i++){
		for(int j = i; j <= l; j++){
			slump[i][j] = -1;
			slimp[i][j] = -1;
		}
	}
}

bool isSlump(int kt, int jw){
	if(slump[kt][jw] != -1) return slump[kt][jw];
	int res;
	if(jw-kt<2 || (s[kt] != 'D' && s[kt] != 'E')) res = 0;
	else{
		int k = kt+1;
		while(k <= jw){
			if(s[k] != 'F') break;
			k++;
		}
		if(k == jw+1 || k == kt+1) res = 0;
		else if(k == jw){
			res = (s[k]=='G');
		}
		else{
			res = isSlump(k, jw);
		}
	}
	slump[kt][jw] = res;
	return res;
}

bool isSlimp(int kt, int jw){
	if(slimp[kt][jw] != -1) return slimp[kt][jw];
	int res;
	if(jw<=kt || s[kt]!='A') res = 0;
	else if(jw==kt+1){
		res = (s[jw]=='H');
	}
	else if(s[jw]!='C'){
		res = 0;
	}
	else{
		res = (s[kt+1]=='B' && kt+2<=jw-1 && isSlimp(kt+2,jw-1)) || (isSlump(kt+1,jw-1));
	}
	slimp[kt][jw] = res;
	return res;
}

int main(){
	int n;
	cout << "SLURPYS OUTPUT" << endl;
	scanf("%d",&n);
	while(n--){
		init();
		bool isSlurpy = 0;
		for(int i = 1; i < l-1; i++){
			if(isSlimp(0, i) && isSlump(i+1, l-1)){
				isSlurpy = 1;
				break;
			}
		}
		cout << (isSlurpy? "YES": "NO") << endl;
	}
	cout << "END OF OUTPUT" << endl;
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator