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
  • 相关阅读:
    POJ 1251Jungle Roads
    ES6---Class基本语法
    浅谈JS的toString
    为什么用Object.prototype.toString.call(obj)检测对象类型?
    JS输出内容为[object Object]与toString
    Sublime text JsFormat插件的安装
    Sublime Text 无法使用Package Control或插件安装失败的解决方法
    Emmet-前端开发神器
    sublime text 3中文版配置--插件ChineseLocalizations
    vs code相关用法
  • 原文地址:https://www.cnblogs.com/Rhythm-/p/9332417.html
Copyright © 2011-2022 走看看