zoukankan      html  css  js  c++  java
  • HDU 1114: Piggy-Bank

    3
    10 110
    2
    1 1
    30 50
    10 110
    2
    1 1
    50 30
    1 6
    2
    10 3
    20 4

    The minimum amount of money in the piggy-bank is 60.
    The minimum amount of money in the piggy-bank is 100.
    This is impossible.

    分析: 完全背包。。

    #include <iostream>
    #include <string>
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <deque>
    #include <map>
    #define range(i,a,b) for(int i=a;i<=b;++i)
    #define LL long long
    #define rerange(i,a,b) for(int i=a;i>=b;--i)
    #define fill(arr,tmp) memset(arr,tmp,sizeof(arr))
    using namespace std;
    int t,dp[10005];
    int u[10005],v[10005];
    void init() {
        cin>>t;
    }
    void solve(){
        while(t--){
            int x,y,n,tmp;
            cin>>x>>y;
            tmp=y-x;
            fill(dp,0x3f3f3f3f);
            dp[0]=0;
            cin>>n;
            range(i,1,n)cin>>u[i]>>v[i];
            range(i,1,n)range(j,v[i],tmp)dp[j]=min(dp[j],dp[j-v[i]]+u[i]);
            if(dp[tmp]==0x3f3f3f3f)cout<<"This is impossible."<<endl;
            else cout<<"The minimum amount of money in the piggy-bank is "<<dp[tmp]<<"."<<endl;
        }
    }
    int main() {
        init();
        solve();
        return 0;
    }
    View Code
  • 相关阅读:
    Linux_day01_primaryCommand
    Variational auto-encoder VS auto-encoder
    python yield generator 详解
    Paper Writing
    DTU_AI lecture 09
    DTU_AI lecture 08
    Attention mechanism
    Energy Journals
    TF + pytorch学习
    expRNN
  • 原文地址:https://www.cnblogs.com/Rhythm-/p/9332417.html
Copyright © 2011-2022 走看看