题目链接: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. 【Intel AF 2.1 学习笔记一】AF程序结构

    Intel App Framework(原jqMobi)是用来开发hybrid app的开源免费框架,被intel收编之后发布了最新的2.1版本,最近正在学习.af的所谓程序结构,就是AF网页的架构, ...

  2. 关于微博开放平台Oauth2.0接入网站应用

    关于什么是微博开放平台及微博开放平台能做什么,咱就不做搜索引擎的搬运工了 这里直接给个链接介绍:微博开放平台 本文只是抛砖引玉,讲讲微博开放平台的基本用法,适合没接触过开放平台的朋友入门学习,老鸟就略 ...

  3. 找不到 android-support-v4 解决办法

    Project->properties->Java Build Path->Libraries->Add External Jars中加入sdk目录下的extras/andro ...

  4. thinkphp 在阿里云上的nginx.config配置

    # For more information on configuration, see: # * Official English Documentation: http://nginx.org/e ...

  5. mysql中,什么是视图,视图的作用是什么?

    需求描述: 在看mysql的视图,对于视图的定义,进行基本的了解,在此记录下. 概念解释: 视图:存储的查询语句,当调用的时候,产生结果集,视图充当的是虚拟表的角色. 测试过程: 说明: 如果要对一张 ...

  6. 第六种方式,python使用cached_property缓存装饰器和自定义cached_class_property装饰器,动态添加类属性(三),selnium webdriver类无限实例化控制成单浏览器。

    使用 from lazy_object_proxy.utils import cached_property,使用这个装饰器. 由于官方的行数比较少,所以可以直接复制出来用自己的. class cac ...

  7. Tree Recovery(前序中序求后序)

    Tree Recovery Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14640   Accepted: 9091 De ...

  8. Eclipse------新建文件时没有JSP File解决方法

    1.为没有web选项的eclipse添加web and JavaEE插件 .在Eclipse中菜单help选项中选择install new software选项 .在work with 栏中输入 Ju ...

  9. 实战c++中的string系列--不要使用memset初始化string(一定别这么干)

    參考链接: http://www.cppblog.com/qinqing1984/archive/2009/08/07/92479.html 百度百科第一次这么给力: void *memset(voi ...

  10. SpringMVC由浅入深day02_5数据回显_6异常处理器

    5 数据回显 5.1 什么数据回显 表单提交失败需要再回到表单页面重新填写,原来提交的数据需要重新在页面上显示. 5.2 pojo数据回显方法 1.springmvc默认对pojo数据进行回显. po ...