POJ 1243 One Person

#include <stdio.h>
#define MAX 31

int numOfGuesses;
int numOfLifelines;
int price[MAX][MAX];

int solve(int guess, int lifeline){
	if (guess == 0){
		return 0;
	}
	if (price[guess][lifeline] != 0){
		return price[guess][lifeline];
	}
	if (lifeline == 0){
		if (price[guess][0] == 0){
			price[guess][0] = guess;
		}
		return price[guess][0];
	} 
	if (price[guess-1][lifeline] == 0){
		price[guess-1][lifeline] = solve(guess - 1, lifeline);
	}
	if (price[guess-1][lifeline - 1] == 0){
		price[guess-1][lifeline - 1] = solve(guess - 1, lifeline - 1);
	}
	price[guess][lifeline] = 1 + price[guess-1][lifeline] + price[guess-1][lifeline - 1];
	return price[guess][lifeline];
}

int main(){
	//freopen("input.txt", "r", stdin);
	int testCase = 1;
	while (1){
		//input
		
		scanf("%d %d", &numOfGuesses, &numOfLifelines);
		if (numOfGuesses == 0 && numOfLifelines == 0){
			return 0;                    
		}
		printf("Case %d: %d\n", testCase, solve(numOfGuesses, numOfLifelines));
		testCase++;
	}
}

你可能感兴趣的:(poj,one,person,1243)