HDU 1950 Bridging signals(DP Dynamic Planning O(n^2))

#include <stdio.h>
#define MAX_POARTS 40000

int numOfTests;
int numOfPorts;
int arrayOfPorts[MAX_POARTS + 1];
//lenOfIS[index]    arrayOfPorts   index   , arrayOfPorts[index] "  "         
int lenOfIS[MAX_POARTS + 1];//length of increasing subsequence
int result;//length of increasing subsequence

int main(){

	scanf("%d", &numOfTests);
	int test;
	for (test = 1; test <= numOfTests; test++){
		scanf("%d", &numOfPorts);
		int indexOfPort;
		for (indexOfPort = 1; indexOfPort <= numOfPorts; indexOfPort++)
			scanf("%d", &arrayOfPorts[indexOfPort]);
		
		result = 0;
		for (indexOfPort = 1; indexOfPort <= numOfPorts; indexOfPort++){
			lenOfIS[indexOfPort] = 1;
			int indexOfBefore;
			for (indexOfBefore = 1; indexOfBefore < indexOfPort; indexOfBefore++)
				if (arrayOfPorts[indexOfBefore] < arrayOfPorts[indexOfPort] && lenOfIS[indexOfBefore] + 1 > lenOfIS[indexOfPort])
					lenOfIS[indexOfPort] = lenOfIS[indexOfBefore] + 1;
			if (lenOfIS[indexOfPort] > result)
				result = lenOfIS[indexOfPort];
		
		}

		printf("%d
", result); } return 0; }

좋은 웹페이지 즐겨찾기