Advertisement
hsiuyee

Problem M. Munich

Jun 10th, 2023
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.62 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define fastio ios::sync_with_stdio(false),cin.tie(0);
  5. #define pll pair<ll,ll>
  6. #define F first
  7. #define S second
  8. #define pb push_back
  9. #define ppb pop_back()
  10. #define mkp make_pair
  11. #define sz(a) (ll)a.size()
  12. #define all(x) x.begin(),x.end()
  13.  
  14. const ll MAXN=1001;
  15. const ll INF=1e18;
  16. const ll MOD=998244353;
  17.  
  18. ll M,N,K;
  19. ll p[4],q[4];
  20. ll dp1[MAXN][MAXN],dp2[MAXN][MAXN];
  21.  
  22. void init(){
  23.     cin>>M>>N>>K;
  24.     for(ll i=0;i<3;i++) cin>>p[i];
  25.     for(ll i=0;i<3;i++) cin>>q[i];
  26.     for(ll i=0;i<=M;i++){
  27.         for(ll j=0;j<=N;j++){
  28.             dp1[i][j]=dp2[i][j]=INF;
  29.         }
  30.     }
  31.     dp1[0][0]=dp2[0][0]=0;
  32.     for(ll i=0;i<=M;i++){
  33.         for(ll j=0;j<=N;j++){
  34.             if(i==0 && j==0) continue;
  35.             if(i>0){
  36.                 dp1[i][j]=min(dp1[i][j],dp1[i-1][j]+p[0]);
  37.                 dp2[i][j]=min(dp2[i][j],dp2[i-1][j]+q[0]);
  38.             }
  39.             if(j>0){
  40.                 dp1[i][j]=min(dp1[i][j],dp1[i][j-1]+p[0]);
  41.                 dp2[i][j]=min(dp2[i][j],dp2[i][j-1]+q[0]);
  42.             }
  43.             if(j>0){
  44.                 dp1[i][j]=min(dp1[i][j],dp1[i][j-1]+p[1]);
  45.                 dp2[i][j]=min(dp2[i][j],dp2[i][j-1]+q[1]);
  46.             }
  47.             for(ll a=0;a<=5;a++){//ๅคงไบบ
  48.                 for(ll c=0;c<=2*(5-a);c++){
  49.                     if(i>=a && j>=c){
  50.                         dp1[i][j]=min(dp1[i][j],dp1[i-a][j-c]+p[2]);
  51.                         dp2[i][j]=min(dp2[i][j],dp2[i-a][j-c]+q[2]);
  52.                     }
  53.                 }
  54.             }
  55.         }
  56.     }
  57.     ll ans=INF;
  58.     for(ll i=0;i<=M;i++){
  59.         for(ll j=0;j<=N;j++){
  60.             ans=min(ans,dp1[i][j]*K+dp2[M-i][N-j]);
  61.         }
  62.     }
  63.     cout<<ans<<"\n";
  64. }
  65.  
  66. void solve(){
  67.    
  68. }
  69.  
  70. signed main(){
  71.     fastio 
  72.     freopen("munich.in","r",stdin);
  73.     freopen("munich.out","w",stdout);
  74.     // ll T;
  75.     // cin>>T;
  76.     // while(T--){
  77.         init();
  78.         solve();
  79.     // }
  80.     return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement