题目1454:Piggy-Bank(完全背包问题)
题目链接: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(完全背包问题)的更多相关文章
- 九度 题目1454:Piggy-Bank 完全背包
题目1454:Piggy-Bank 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:1584 解决:742 题目描述: Before ACM can do anything, a budg ...
- ACM Piggy Bank
Problem Description Before ACM can do anything, a budget must be prepared and the necessary financia ...
- 背包九讲 附:USACO中的背包问题
附:USACO中的背包问题 USACO是USA Computing Olympiad的简称,它组织了很多面向全球的计算机竞赛活动. USACO Trainng是一个很适合初学者的题库,我认为它的特色是 ...
- 杭电 1114 Piggy-Bank 完全背包问题
Piggy-Bank Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- luogu P3420 [POI2005]SKA-Piggy Banks
题目描述 Byteazar the Dragon has NN piggy banks. Each piggy bank can either be opened with its correspon ...
- 洛谷 P3420 [POI2005]SKA-Piggy Banks
P3420 [POI2005]SKA-Piggy Banks 题目描述 Byteazar the Dragon has NN piggy banks. Each piggy bank can eith ...
- [Luogu3420][POI2005]SKA-Piggy Banks
题目描述 Byteazar the Dragon has NNN piggy banks. Each piggy bank can either be opened with its correspo ...
- 【阿菜Writeup】Security Innovation Smart Contract CTF
赛题地址:https://blockchain-ctf.securityinnovation.com/#/dashboard Donation 源码解析 我们只需要用外部账户调用 withdrawDo ...
- hdu 2191多重背包
悼念512汶川大地震遇难同胞——珍惜现在,感恩生活 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Jav ...
随机推荐
- PHP数组排序函数array_multisort()函数详解(二)
array_multisort()这个函数可以对多个PHP数组进行排序,排序结果是所有的数组都按第一个数组的顺序进行排列 例如array_multisort($a,$b),$a,$b是两个数组,如果排 ...
- libstdc++.so.5: undefined reference to `memcpy@GLIBC_2.14'
没有别的原因: 找正确的 libstdc++.so.5 包就成. 我这儿有,需要的可以下载奥!
- UGUI之不规则按钮的响应区域
比如一些不规则按钮最好可以设置它的响应区域.如下图所示,用Polygon Collider2D组件圈出精灵响应事件的区域. 注意 IsRaycastLocationValid 的判断区域是RectTr ...
- 如何获取ABBYY FineReader 12注册码-激活码-序列号
提及OCR文字识别软件,相信不少人会脱口而出ABBYY FineReader,这款软件当前最新版本为FineReader 12,是市场领先的OCR图文识别软件,不仅可以将纸质文档和PDF文件以及图像文 ...
- IT运维队伍的管理
如何建设一支能够解决问题.创造价值.有活力的.不断进取的IT运维团队,并带领这支团队,充分发挥这个团队的优势力量,是运维业务有效开展的关键.运维 策略是直接体现运维业务的经济价值所在.好的运维措施.方 ...
- python打造线程池
# coding=utf-8 import threading import Queue import time import traceback class ThreadPoolExecutor(o ...
- MAC下Android的Eclipse开发环境的搭建 转自MacroCheng
原文地址: http://www.cnblogs.com/macro-cheng/archive/2011/09/30/android-001.html 一.Eclipse的下载 到网站:http: ...
- PMP考试相关
知识点:http://www.cnblogs.com/allenblogs/tag/PMbook/ 读书笔记: http://www.cnblogs.com/lensin/category/45538 ...
- ios开发之--多个按钮单选效果
开发项目时,有很多场景需要用到按钮单选效果,例如充值页面,选择标签页面等,具体实现代码如下: 1,创建 -(UIView *)headerView { CGFloat width = (Kscreen ...
- 【代码审计】DouPHP_v1.3代码执行漏洞分析
0x00 环境准备 DouPHP官网:http://www.douco.com/ 程序源码下载:http://down.douco.com/DouPHP_1.3_Release_20171002. ...