题目链接:http://ac.jobdu.com/problem.php?pid=1454

详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus

参考代码:

//
// 1454 Piggy-Bank.cpp
// Jobdu
//
// Created by PengFei_Zheng on 25/04/2017.
// Copyright © 2017 PengFei_Zheng. All rights reserved.
// #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <cmath>
#include <limits.h>
#define MAX_SIZE 10001
#define MAX_NUM 501 using namespace std; struct Coin{
int value;
int space;
}; int t, e, f, n;
int dp[MAX_SIZE];
Coin coin[MAX_NUM]; int main(){
scanf("%d",&t);
while(t--){
scanf("%d%d",&e,&f);
scanf("%d",&n);
int space = f - e;
for(int i = ; i <= n ; i++){
scanf("%d%d",&coin[i].value,&coin[i].space);
}
for(int i = ; i <= space ; i++){
i == ? dp[i] = : dp[i] = INT_MAX;
}
for(int i = ; i <= n ; i++){
for(int j = coin[i].space ; j <= space ; j++){
if(dp[j-coin[i].space] != INT_MAX)
dp[j] = min(dp[j], dp[j-coin[i].space]+coin[i].value);
}
}
if(dp[space] != INT_MAX)
printf("The minimum amount of money in the piggy-bank is %d.\n",dp[space]);
else
printf("This is impossible.\n");
}
return ;
}
/**************************************************************
Problem: 1454
User: zpfbuaa
Language: C++
Result: Accepted
Time:50 ms
Memory:1560 kb
****************************************************************/

题目1454:Piggy-Bank(完全背包问题)的更多相关文章

  1. 九度 题目1454:Piggy-Bank 完全背包

    题目1454:Piggy-Bank 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:1584 解决:742 题目描述: Before ACM can do anything, a budg ...

  2. ACM Piggy Bank

    Problem Description Before ACM can do anything, a budget must be prepared and the necessary financia ...

  3. 背包九讲 附:USACO中的背包问题

    附:USACO中的背包问题 USACO是USA Computing Olympiad的简称,它组织了很多面向全球的计算机竞赛活动. USACO Trainng是一个很适合初学者的题库,我认为它的特色是 ...

  4. 杭电 1114 Piggy-Bank 完全背包问题

    Piggy-Bank Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  5. luogu P3420 [POI2005]SKA-Piggy Banks

    题目描述 Byteazar the Dragon has NN piggy banks. Each piggy bank can either be opened with its correspon ...

  6. 洛谷 P3420 [POI2005]SKA-Piggy Banks

    P3420 [POI2005]SKA-Piggy Banks 题目描述 Byteazar the Dragon has NN piggy banks. Each piggy bank can eith ...

  7. [Luogu3420][POI2005]SKA-Piggy Banks

    题目描述 Byteazar the Dragon has NNN piggy banks. Each piggy bank can either be opened with its correspo ...

  8. 【阿菜Writeup】Security Innovation Smart Contract CTF

    赛题地址:https://blockchain-ctf.securityinnovation.com/#/dashboard Donation 源码解析 我们只需要用外部账户调用 withdrawDo ...

  9. hdu 2191多重背包

    悼念512汶川大地震遇难同胞——珍惜现在,感恩生活 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Jav ...

随机推荐

  1. 由SecureCRT命令行快捷键谈学习思想

    由学习linux SecureCRT命令行常用快捷键开始谈起! 1)老男孩说,抓重点(重点非难点) 任何一个领域.学科,任何一个职位.工作,都有学不完的知识,优秀的学生总能抓住重点去学习,如果泛泛的去 ...

  2. Github 提交本地代 到远程 菜鸟 简明教程

    方法1: 1. 右击项目文件夹  Git Bash Here 或   Git clone  Url  远程仓库地址  Directory  本地文件夹 2. 拷贝(新建)项目文件 3. 添加项目文件 ...

  3. C# 使用 Task 替换 ThreadPool ,异步监测所有线程(任务)是否全部执行完毕

    using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Collections.Generic; using System.T ...

  4. [lua, mysql] 将多条记录数据组合成一条sql插入语句(for mysql)

    -- 演示将多条记录数据组合成一条sql插入语句(for mysql) function getTpl0(tname) -- 获取表各个字段 local t = { tpl_pack = {" ...

  5. 管道符和作业控制 shell变量 环境变量配置文件

    8.6 管道符和作业控制 8.7/8.8 shell变量 8.9 环境变量配置文件 管道符和作业控制 管道符:表示把一个文件的输出内容传送到后面的命令 grep  用来过滤指定关键词的命令 “|” 为 ...

  6. git恢复删除的分支及内容

    git 删除分支git branch -D 分支名 git查看分支 git branch -a git 删除远程分支 git push origin :分支名 这里注意:git分支提交并且push了, ...

  7. TensorFlow安装,升级,基本操作

    一. 安装 ubuntu 16 python 2.7 pip install tensorflow 测试安装完成效果: 查看tensorFlow版本python import tensorflow a ...

  8. 比SRCNN效果好的传统超分辨率算法汇总

    1.基于深度协作表达的人脸图像超分辨率算法研究与应用_百度学术 采用一种深度协作表达算法框架,构造深度的多线性模型 分段拟合高低分辨率图像块之间的非线性关系,本文算法简洁高效,提供了一种新的深度学习模 ...

  9. Centos7.3.1611安装mysql5.7.18 rpm教程 并设置datadir

    一.卸载MariaDB CentOS7默认安装MariaDB而不是MySQL,而且yum服务器上也移除了mysql相关的软件包.因为MariaDB和MySQL可能会冲突,故先卸载MariaDB. 1. ...

  10. sed在替换的时候,使用变量中的值?如何在sed实现变量的替换?获取到变量中的值?

    需求描述: 今天在做nrpe配置的时候,想要通过批量的方式来将定义文件中的IP给替换掉 开始做的时候没有成功,报错了.在此记录下,如何实现,获取到变量的值,然后 进行替换. 操作过程: 1.原文件的内 ...