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 1201 Intervals 差分约束系统
    poj 3237 Tree 树链剖分+线段树
    hdu 2256 Problem of Precision 构造整数 + 矩阵快速幂
    hdu 5451 Best Solver 矩阵循环群+矩阵快速幂
    hdu 5769 Substring 后缀数组 + KMP
    hdu 5755 2016 Multi-University Training Contest 3 Gambler Bo 高斯消元模3同余方程
    hdu 5690 2016"百度之星"
    hdu 5738 2016 Multi-University Training Contest 2 Eureka 计数问题(组合数学+STL)
    hdu 5719 BestCoder 2nd Anniversary B Arrange 简单计数问题
    hdu 5720 BestCoder 2nd Anniversary Wool 推理+一维区间的并
  • 原文地址:https://www.cnblogs.com/Rhythm-/p/9332417.html
Copyright © 2011-2022 走看看