zoukankan      html  css  js  c++  java
  • poj1384

    //
    //  main.cpp
    //  poj1384
    //
    //  Created by 韩雪滢 on 12/13/16.
    //  Copyright © 2016 韩雪滢. All rights reserved.
    //
    
    #include <iostream>
    #include <algorithm>
    using namespace std;
    
    int main() {
        int T;
        cin >> T;
        for(int i=0;i<T;i++){
            int E,F,N;
            cin >> E >> F;
            
            int *allweight = new int[F-E+1];
            allweight[0] = 0;
            for(int k=1; k<F-E+1;k++)
                allweight[k] = 10000000;
            
            cin >> N;
            for(int j=0;j<N;j++){
                int P,W;
                cin >> P >> W;
                for(int n=W;n<=F-E;n++)
                    allweight[n] = min(allweight[n],allweight[n-W]+P);
    
                
            }
            if(allweight[F-E] != 10000000){
            cout <<"The minimum amount of money in the piggy-bank is " <<allweight[F-E] << "."<< endl;
            }else{
                cout << "This is impossible." << endl;
            }
        }
        return 0;
    }
  • 相关阅读:
    常用命令
    经典算法
    框架
    计算机网络
    设计模式
    JVM
    数据库
    多线程
    Java中HashMap的底层实现原理
    构建大小顶堆
  • 原文地址:https://www.cnblogs.com/HackHer/p/6171719.html
Copyright © 2011-2022 走看看