HDU 1712 ACboy needs your help(패키지 그룹)

#include <stdio.h>
#define MAX 101

int numOfCourses, mostDays;
int profit[MAX][MAX];
int maxProfit[MAX];

int main(){
	
	while (scanf("%d%d", &numOfCourses, &mostDays) != EOF){
		if (numOfCourses == 0 && mostDays == 0)
			break;

		int course, days;
		for (course = 1; course <= numOfCourses; course++)
			for (days = 1; days <= mostDays; days++)
				scanf("%d", &profit[course][days]);

		int totalDays;
		for (totalDays = 1; totalDays <= mostDays; totalDays++)
			maxProfit[totalDays] = 0;

		int preCourses, tempProfit;
		for (preCourses = 1; preCourses <= numOfCourses; preCourses++)
			for (totalDays = mostDays; totalDays >= 1; totalDays--)
				for (days = 1; days <= totalDays; days++){
					tempProfit = maxProfit[totalDays - days] + profit[preCourses][days];
					if (tempProfit > maxProfit[totalDays])
						maxProfit[totalDays] = tempProfit;
				}
				
		printf("%d
", maxProfit[mostDays]); } return 0; }

좋은 웹페이지 즐겨찾기