Tarango

Untitled

Aug 8th, 2015
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. //============================================================================
  2. // Name        : ACM
  3. // Author      : Tarango Khan
  4. // Team        : BRACU Byteheads
  5. //============================================================================
  6.  
  7. #include <bits/stdc++.h>
  8. using namespace std;
  9. int inf = 999999999;
  10.  
  11. int DP[51][1001];
  12. int N,K;
  13.  
  14. int call(int ball,int floor){
  15.     if(floor <= 1) return floor;
  16.     if(ball == 1) return floor;
  17.     if(DP[ball][floor] != -1) return DP[ball][floor];
  18.  
  19.     int res = inf;
  20.     for(int f = 1;f<=floor;f++){
  21.         int ret1 = call(ball-1,f-1);
  22.         int ret2 = call(ball,floor-f);
  23.         res = min(res,max(ret1,ret2));
  24.     }
  25.     return DP[ball][floor] = res + 1;
  26. }
  27.  
  28. int main() {
  29.     int nCase,tst;
  30.     string s;
  31.     cin >> nCase;
  32.     memset(DP,-1,sizeof(DP));
  33.     for(int cs = 1;cs<=nCase;cs++){
  34.         cin >> tst >> N >> K;
  35.         int res = call(N,K);
  36.         printf("%d %d\n",cs,res);
  37.     }
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment