Last active
April 27, 2017 10:52
-
-
Save znxkznxk1030/2a0f96165c67834cb6f015fc662f5eb6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <stdio.h> | |
#include <iostream> | |
#include <stack> | |
#include <cstring> | |
#define ll long long int | |
#define MAX(a,b) (a)>(b)?(a):(b) | |
#define MIN(a,b) (a)>(b)?(b):(a) | |
#define pii pair<int , int> | |
#define time first | |
#define cost second | |
using namespace std; | |
pii sch[123]; | |
int dp[123]; | |
int n; | |
int main() | |
{ | |
scanf("%d", &n); | |
for (int i = 1; i <= n; i++) | |
{ | |
int a, b; | |
scanf("%d %d", &a, &b); | |
sch[i] = pii(a, b); | |
} | |
int ans = 0; | |
for (int i = 1; i <= n + 1; i++) | |
{ | |
for (int j = 1; j <= 5; j++) | |
{ | |
int prev = i - j; | |
if (sch[prev].time == j) | |
dp[i] = MAX(dp[i], dp[prev] + sch[prev].cost); | |
else dp[i] = MAX(dp[prev], dp[i]); | |
} | |
} | |
printf("%d\n", dp[n + 1]); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment