티스토리 뷰

알고리즘

이벤트 문제

path7inder 2014. 9. 24. 18:28
프로그램 명: ncpc_event
제한시간: 1 초

[문제요약] 입력 예시

3 1000 2 3 //미팅의 참가자수 , 예산 , 호텔의수 , 가능한 주(1~weekend)

200 // 첫번째 호텔의 인당 숙박비
0 2 2 //첫번째 호텔의  각 주말마다 숙박가능한 인원 

300 // 두번째 호텔의 ...
27 3 20

가능한 최소 경비를 출력한다. 가능하지 않으면 'stay home' 을 출력 (단, 모두 같은 호텔 , 같은 날 숙박해야 한다.)


As you didn't show up to the yearly general meeting of the Nordic Club of Pin Collectors, you were unanimously elected to organize this years excursion to Pin City. You are free to choose from a number of weekends this autumn, and have to find a suitable hotel to stay at, preferably as cheap as possible.

You have some constraints: The total cost of the trip must be within budget, of course. All participants must stay at the same hotel, to avoid last years catastrophe, where some members got lost in the city, never being seen again.

입력

  • The first line of input consists of four integers: 1 <= N <= 200, the number of participants, 1 <= B <= 500000, the budget, 1 <= H <= 18, the number of hotels to consider, and 1 <= W <= 13, the number of weeks you can choose between.
  • Then follow two lines for each of the H hotels.
    • The first gives 1 <= p <= 10000, the price for one person staying the weekend at the hotel.
    • The second contains W integers, 0 <= a <= 1000, giving the number of available beds for each weekend at the hotel.

출력

Output the minimum cost of the stay for your group, or "stay home" if nothing can be found within the budget.

입출력 예

입력

3 1000 2 3
200
0 2 2
300
27 3 20

출력

900

입력

5 2000 2 4
300
4 3 0 4
450
7 8 0 13

출력

stay home
출처:ncpc/2008/Problem E

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <stdio.h>
 
#define INF 2000001
 
int main()
{
    int N,B,H,W;
    int min = INF;
 
    scanf("%d %d %d %d",&N,&B,&H,&W);
 
    for(int i=0; i<H; i++)
    {
        int p;
        scanf("%d",&p);
        for(int j=0; j<W; j++)
        {
            int a;
            scanf("%d",&a);
            if(a >= N){
                int cost = p * N;
                if(cost <= B && cost < min){
                    min = cost; // 모든 경우의 수를 검사 최소 비용을 추출
                }
            }
        }
    }
 
    if(min == INF) printf("stay home\n"); // 없으면 집에서 쉬기
    else printf("%d\n",min);
}


'알고리즘' 카테고리의 다른 글

세 거듭제곱 문제  (0) 2014.09.24
소인수 분해 문제  (0) 2014.09.24
Collatz 추측 문제  (0) 2014.09.24
친구수 문제  (0) 2014.09.24
자물쇠 풀기 문제  (0) 2014.09.18
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함