题目链接: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. 允许root远程登录Solaris

    注释掉:/etc/default/login文件中CONSOLE=/dev/console

  2. MyBatis之one2one与one2many

    <!--顾客信息表,其中一个顾客对应一个国家,一个顾客对应多个订单--> <resultMap id="customerResultMap" type=" ...

  3. python的sciter库Pysciter安装教程(win32 + win64)

    Pysciter是一个结合HTML与Python编写桌面软件个三方库 注:无论是32位还是64位电脑,建议安装32位的sciter,这样写出来的软件可以在win32和win64电脑上都可以运行(前提p ...

  4. 配置IP

    配置目的:配置IP为静态,让IP地址不变,方便长时间连接. 几个命令: dhclient 自动获取IP; 杀死进程:dhclient -r ip addr 显示网卡情况,了解到IP地址: 编辑配置文件 ...

  5. Thinkphp5笔记四:设置模板路径

    默认的模板路径在模块/view文件里面.如果你觉得这样不太方便管理,想要把他设置Template目录下,可以这样做. 模板参数 ,能够影响的它参数,是当前模块下config.php template- ...

  6. flask with gae开发小结

    最近因为要重写之前发布在GAE上的一个博客,又回顾了一下python,同时,因为用的flask,gae等等,一道写一些小总结,供日后查阅. 1, slugify 其实这个问题可以不考虑,只要你愿意用中 ...

  7. hbase深入了解

    http://blog.csdn.net/u010967382/article/details/37878701?utm_source=tuicool&utm_medium=referral ...

  8. PO页面对象模式封装

    PO的主要价值体现在对界面交互细节的封装,这样可以使测试案例可以更关注与业务而非界面细节,提高测试案例的可读性.   以传统的登陆页面为例實現PO模式,因为每个用例中都需要登陆. 其中需要使用Page ...

  9. VCL 中的 Windows API 函数(4): AdjustWindowRectEx

    AdjustWindowRectEx 用在了 Forms.DBCtrls 单元. AdjustWindowRectEx 可以根据窗口样式获取的边缘尺寸. 测试: var   R: TRect; beg ...

  10. Linux安装bundle

    安装bundle文件的方法: cd 到文件目录再用sudo chmod +x XXXXXXX.bundle 加权限最后 ./XXXXXXXX.bundle 就行了. 第一步:sudo chmod +x ...