Advertisement
_no0B

Untitled

Nov 7th, 2021
680
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.63 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. #define N ((int)(1e5 + 5))
  4. #define MAX ((int)2e9 + 5)
  5. #define MAXL ((ll)1e18 + 5)
  6. #define MOD ((int)(1e9 + 3))
  7. #define endl "\n"
  8. #define fastio ios_base::sync_with_stdio(false),cin.tie(NULL);
  9.  
  10.  
  11. using namespace std;
  12.  
  13. // fastio
  14. //ios_base::sync_with_stdio(false);
  15. //cin.tie(NULL);
  16.  
  17. int n , dpp[105][N] , val[105]  ,cnt[105];
  18.  
  19. int call(int idx , int tot)
  20. {
  21.     if(tot < 0) return MAX;
  22.     if(idx > n){
  23.         if(tot == 0) return 0;
  24.         return MAX;
  25.     }
  26.     if(dpp[idx][tot] != -1) return dpp[idx][tot];
  27.     int ans = MAX;
  28.     ans = min(ans , call(idx , tot - val[idx]) + 1);
  29.     if(call(idx+1,tot) != MAX) ans = 0;
  30.     if(ans > cnt[idx]) ans = MAX;
  31.     return dpp[idx][tot] = ans;
  32. }
  33.  
  34.  
  35.  
  36. int main()
  37. {
  38. /// problem: https://lightoj.com/problem/coin-change-iii
  39.     fastio;
  40.     int t , caseno = 1;
  41.     cin>>t;
  42.     while(t--){
  43.         int tot , ans = 0;
  44.         cin>>n>>tot;
  45.         for(int i = 1 ; i<=n ; i++) cin>>val[i];
  46.         for(int i = 1 ; i<=n ; i++) cin>>cnt[i];
  47.         for(int j = 1 ; j<=tot ; j++) dpp[n+1][j] = MAX;
  48.         dpp[n+1][0] = 0;
  49.         for(int i = n ; i>0 ; i--){
  50.             for(int j = 0 ; j<=tot ; j++){
  51.                 int ans = MAX;
  52.                 if(dpp[i+1][j] != MAX) ans = 0;
  53.                 if(j - val[i] >= 0) ans = min(ans , dpp[i][j-val[i]] + 1);
  54.                 if(ans > cnt[i]) ans = MAX;
  55.                 dpp[i][j] = ans;
  56.             }
  57.         }
  58.  
  59.         for(int i = 1 ; i<=tot ; i++){
  60.             if(dpp[1][i] != MAX) ans++;
  61.         }
  62.  
  63.         cout<<"Case "<<caseno++<<": "<<ans<<endl;
  64.     }
  65.     return 0;
  66. }
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement