daily pastebin goal
6%
SHARE
TWEET

Untitled

a guest Jul 12th, 2018 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <cstdio>
  2. #include <algorithm>
  3. #define MAXN 50
  4. #define MAXC 812
  5. #define INF 0x3f3f3f3f
  6. using namespace std;
  7. int g[MAXN], y[MAXN], dp[MAXN][MAXC][MAXC], seen[MAXN][MAXC][MAXC], n, TC =0;
  8.  
  9. int sol(int idx, int yel, int green){
  10.     if(yel <0 || green <0)
  11.         return -INF;
  12.     if(idx > n)
  13.         return 0;
  14.     if(seen[idx][yel][green] == TC)
  15.         return dp[idx][yel][green];
  16.  
  17.     seen[idx][yel][green] = TC;
  18.     return dp[idx][yel][green] = max(sol(idx+1, yel, green), 1+sol(idx+1, yel+y[idx], g[idx]+green));
  19. }
  20. int main()
  21. {
  22.     int a, b;
  23.     while(scanf("%d", &n)!=EOF){
  24.         scanf("%d %d", &a, &b);
  25.         ++TC;
  26.         for(int i = 1; i<=n; ++i)
  27.             scanf("%d %d", g+i, y+i);
  28.  
  29.         printf("%d\n", sol(1, b,a));
  30.     }
  31. }
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