Created
May 9, 2021 06:17
-
-
Save E869120/7e24442cf50f6636376eb128830ee174 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
using namespace std; | |
int N, L; | |
int V[109], W[109], C[109]; | |
int dp[109][1009]; | |
vector<pair<int, int>> vec[109]; | |
int main() { | |
// Step #1. 入力 | |
cin >> N >> L; | |
for (int i = 1; i <= N; i++) cin >> V[i] >> W[i]; | |
// Step #2. 種類ごとに分ける | |
for (int i = 1; i <= 5; i++) C[i] = 0; | |
for (int i = 11; i <= 20; i++) C[i] = 1; | |
for (int i = 21; i <= 25; i++) C[i] = 2; | |
for (int i = 26; i <= 30; i++) C[i] = 3; | |
for (int i = 31; i <= 35; i++) C[i] = 4; | |
for (int i = 6; i <= 10; i++) C[i] = 5; | |
for (int i = 36; i <= 38; i++) C[i] = 5; | |
for (int i = 39; i <= 43; i++) C[i] = 6; | |
for (int i = 44; i <= 46; i++) C[i] = 7; | |
for (int i = 1; i <= N; i++) { | |
vec[C[i]].push_back(make_pair(V[i], W[i])); | |
} | |
for (int i = 0; i <= 7; i++) vec[i].push_back(make_pair(0, 0)); | |
// Step #3. 動的計画法・出力 | |
for (int i = 0; i <= 7; i++) { | |
for (int j = 0; j <= L; j++) { | |
for (pair<int, int> k : vec[i]) { | |
if (j < k.second) continue; | |
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - k.second] + k.first); | |
} | |
} | |
} | |
cout << "Calories = " << dp[8][L] << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment