fragment-header
fragment-markdown
홈
로그인
로그아웃
내 블로그
설정
로그인
백준 5207 (C++) Orange Bowl
최초 업로드: 2025-09-23 16:17:18
최근 수정 시간: 2025-09-23 16:17:18
게시자: rlatjwls3333
카테고리: 백준
조회수: 6
# [Gold IV] Orange Bowl [문제 링크](https://www.acmicpc.net/problem/5207) ## 문제 설명 <p>It’s late in the Orange Bowl Football game, and USC is trailing by 4 points, needing desperately to score another touchdown.<sup>3</sup> So coach Pete Carroll consults his newest weapon: a play strategy evaluator written at the USC programming contest.</p> <p>While football is a somewhat more complicated game, we can simplify it as follows: USC is currently n yards away from the end zone (1 ≤ n ≤ 100). The coach needs to decide on a sequence of plays to get the ball to the end zone as safely as possible. For each play, the coach can choose among m different plays (1 ≤ m ≤ 1000). Each play is characterized by two numbers: its yard gain g, and its success probability p. Here g is an integer between 1 and 100, and p is a real number between 0 and 1. This means that the play succeeds with probability p, and if it does, it moves USC g yards closer to the end zone. If it fails, the ball is turned over, and USC loses the game.</p> <p>The goal is to select a sequence of plays (which can have repetitions), such that the total yard gain is at least n, and the total success probability is maximized. We assume that the plays all succeed independently, i.e., the success probability of a sequence is the product of the individual probabilities.</p> <p><sup>3</sup>Yeah, right! Like USC is going to be trailing in football games any time soon.</p> ## 입력 <p>The first line contains a number K ≥ 1, which is the number of input data sets in the file. This is followed by K data sets of the following form:</p> <p>The first line of each data set contains the numbers n and m. This is followed by m lines, each containing the two numbers g<sub>i</sub> and p<sub>i</sub> for one play i.</p> ## 출력 <p>For each data set, first output “Data Set x:” on a line by itself, where x is its number. Then, output on one line the overall success probability of the sequence of plays most likely to get USC to the end zone, rounded to two decimals. (You do not need to output the actual sequence.)</p> ## 풀이 저장되는 값이 실수인 냅색 문제입니다. ``` c++ #include<bits/stdc++.h> using namespace std; typedef long double ld; ld minCost[101]; int main() { ios::sync_with_stdio(0); cin.tie(0); int k; cin >> k; for(int tc=1;tc<=k;tc++) { int n, m; cin >> n >> m; memset(minCost, 0, sizeof minCost); minCost[0]=1; while(m--) { int g; ld p; cin >> g >> p; for(int i=g;i<=n;i++) minCost[i] = max(minCost[i], minCost[i-g]*p); } cout << fixed << setprecision(2) << "Data Set " << tc << ":\n" << minCost[n] << '\n'; } } ```