题目链接: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. Eclipse文件首部自动加 作者时间

    Window -> Preferences -> Java -> Code Style -> Code templates -> (in right-hand pane) ...

  2. VS 附加进程调试 Web项目

    一.新建IIS站点物理路径要指定项目开发Web路径(不可以发布), 二.Host文件网站域名要指定127.0.0.1 三.打开项目目录找到.vs\config\applicationhost.conf ...

  3. php写文件操作

    function writeLog($file, $msg, $mode='a+') { $fp = fopen($file, $mode); if(flock($fp, LOCK_EX)) { fw ...

  4. Getting Started with Google Guava.pdf

  5. 手机浏览器中屏蔽img的系统右键菜单context menu

    我们知道通过oncontextmenu事件可以屏蔽浏览器右键菜单 $('img').on("contextmenu",function(E){E.preventDefault(); ...

  6. 17 HTTP编程入门

    http请求原理 http请求原理我就不多说了,网上一搜就能搜索到,下面我注意是记录下http模块的使用方法 http 模块 HTTP-server hello world 我们使用HandleFun ...

  7. ssh跟ssm的区别

    SSH跟SSM的区别 SSH指的是:spring+Struts+hibernate:而SSM指的是:spring +SpringMVC + MyBatis. 1.Spring是是开源框架,是轻量级的I ...

  8. mongodb 初学 目录

    mongodb 初学 索引 啦啦啦 MongoDB 教程 NoSQL 简介 MongoDB 简介 Windows 平台安装 MongoDB Linux平台安装MongoDB mongodb 在 Ubu ...

  9. 7 -- Spring的基本用法 -- 12... Spring 3.0 提供的表达式语言(SpEL)

    7.12 Spring 3.0 提供的表达式语言(SpEL) Spring表达式语言(简称SpEL)是一种与JSP 2 的EL功能类似的表达式语言,它可以在运行时查询和操作对象图.支持方法调用和基本字 ...

  10. scala try monad

    当输入的数据格式不正确时,ActivityData 中会出现 OutofIndex 错误,但更多的时候我们只关心想要的结果而不想了解出现了怎样的错误,然后会写出这样的代码   def parseCSV ...