Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define ll long long
- #define N ((int)(1e5 + 5))
- #define MAX ((int)2e9 + 5)
- #define MAXL ((ll)1e18 + 5)
- #define MOD ((int)(1e9 + 3))
- #define endl "\n"
- #define fastio ios_base::sync_with_stdio(false),cin.tie(NULL);
- using namespace std;
- // fastio
- //ios_base::sync_with_stdio(false);
- //cin.tie(NULL);
- int n , dpp[105][N] , val[105] ,cnt[105];
- int call(int idx , int tot)
- {
- if(tot < 0) return MAX;
- if(idx > n){
- if(tot == 0) return 0;
- return MAX;
- }
- if(dpp[idx][tot] != -1) return dpp[idx][tot];
- int ans = MAX;
- ans = min(ans , call(idx , tot - val[idx]) + 1);
- if(call(idx+1,tot) != MAX) ans = 0;
- if(ans > cnt[idx]) ans = MAX;
- return dpp[idx][tot] = ans;
- }
- int main()
- {
- /// problem: https://lightoj.com/problem/coin-change-iii
- fastio;
- int t , caseno = 1;
- cin>>t;
- while(t--){
- int tot , ans = 0;
- cin>>n>>tot;
- for(int i = 1 ; i<=n ; i++) cin>>val[i];
- for(int i = 1 ; i<=n ; i++) cin>>cnt[i];
- for(int j = 1 ; j<=tot ; j++) dpp[n+1][j] = MAX;
- dpp[n+1][0] = 0;
- for(int i = n ; i>0 ; i--){
- for(int j = 0 ; j<=tot ; j++){
- int ans = MAX;
- if(dpp[i+1][j] != MAX) ans = 0;
- if(j - val[i] >= 0) ans = min(ans , dpp[i][j-val[i]] + 1);
- if(ans > cnt[i]) ans = MAX;
- dpp[i][j] = ans;
- }
- }
- for(int i = 1 ; i<=tot ; i++){
- if(dpp[1][i] != MAX) ans++;
- }
- cout<<"Case "<<caseno++<<": "<<ans<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement