fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. vector<vector<long long> > dp(2000,vector<long long>(2000,-1));
  4. long long solve(long long i,long long j,int last){
  5. if(i<=0||j<=0)return 0;
  6. if(dp[i][j]!=-1)return dp[i][j];
  7. if(last!=0){
  8. return dp[i][j]= 1 + solve(i+3,j+2,0);
  9. }
  10. return dp[i][j]= 1 + max(solve(i-5,j-10,1),solve(i-20,j+5,2));
  11. }
  12. int main(){
  13. ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  14. int t;
  15. cin>>t;
  16.  
  17. while(t--){
  18. long long h,a;
  19. cin>>h>>a;
  20. cout<<solve(h+3,a+2,0)<<"\n";
  21. }
  22. return 0;
  23. }
Success #stdin #stdout 0.01s 34920KB
stdin
3
2 10
4 4
20 8
stdout
1
1
5