daily pastebin goal
75%
SHARE
TWEET

Untitled

a guest Dec 13th, 2018 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream> using namespace std; int table[3][12] = { {5, 9, 12, 10, 15, 18, 20, 50, 27, 30, 34, 38}, {7, 9, 11, 40, 16, 19, 21, 10, 25, 28, 35, 40}, {6, 10, 13, 50, 16, 18, 21, 15, 25, 26, 29, 33} }; int tableRead(int stage, int u) { if (u == 0) { return 0; } else { return table[stage][u - 1]; } } int main() { //3rd stage int stage = 3; int S2[12]; for (int i = 0; i <= 12; i++) { S2[i] = tableRead(stage - 1, i); cout << S2[i] << endl; } //2nd stage stage = 2; int u; int S1[12]; int max = 0; for (int x1 = 0; x1 <= 12; x1++) { for (int x2 = 12; x2 >= 0; x2--) { u = x2 - x1; if (tableRead(stage - 1, u) + S2[x2] > max) max = tableRead(stage - 1, u); if (u == 0) { S1[x1] = max; break; } } } for (int i = 0; i <= 12; i++) { cout << S1[i] << endl; } //1st stage stage = 1; int S0; int max = 0; int x0 = 12; for (int x1 = 12; x1 >= 0; x1--) { u = x1 - x0; if (tableRead(stage - 1, u) + S1[x1] > max) max = tableRead(stage - 1, u); if (u == 0) { S0 = max; break; } } return 0; }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top