hdu1114 Piggy-Bank ——完全背包
link:http://acm.hdu.edu.cn/showproblem.php?pid=1114
只不过求得是最小值。没什么可说的,连我都会做……o(╯□╰)o
/*
ID: zypz4571
LANG: C++
TASK: pig.cpp
*/ #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <queue>
#include <deque>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <functional>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
#include <ctime>
#include <iterator>
const int INF = 0x3f3f3f3f;
const int dir[][] = {{-,},{,},{,-},{,},{-,-},{-,},{,-},{,}};
using namespace std;
int f[],c[],w[], V, n;
void completepack(int c,int w) {
for(int v=c;v<=V;++v)
f[v]=min(f[v],f[v-c]+w);
}
int main ( int argc, char *argv[] )
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
ios::sync_with_stdio(false);
int t; cin>>t;
while (t--) {
int e, F; cin>>e>>F; V=F-e; cin>>n;
for(int i=;i<n;++i) cin>>c[i]>>w[i];
memset(f,INF,sizeof(f)); f[]=;
for (int i=;i<n;++i) completepack(w[i],c[i]);
if(f[V]==INF) cout<<"This is impossible.\n";
else cout<<"The minimum amount of money in the piggy-bank is "<<
f[V]<<".\n";
}
return EXIT_SUCCESS;
} /* ---------- end of function main ---------- */
o(╯□╰)o
hdu1114 Piggy-Bank ——完全背包的更多相关文章
- BZOJ 1531: [POI2005]Bank notes( 背包 )
多重背包... ---------------------------------------------------------------------------- #include<bit ...
- hdu1114 dp(完全背包)
题意:已知空钱罐质量和满钱罐质量(也就是知道钱罐里的钱的质量),知道若干种钱币每种的质量以及其价值,钱币都是无限个,问最少钱罐中有多少钱. 这个题在集训的时候学长给我们做过,所以你会做是应该的,由于已 ...
- kuangbin专题十二 HDU1114 Piggy-Bank (完全背包)
Piggy-Bank Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- HDU1114 Piggy-Bank 【全然背包】
Piggy-Bank Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- HDU1114 Piggy-Bank —— DP 完全背包
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1114 Piggy-Bank Time Limit: 2000/1000 MS (Java/ ...
- HDU1114 Piggy-Bank (完全背包)
完全背包模板,和01背包相比不用倒推,因为一种可以选多个. 这道题求最小,dp数组初始化为无穷即可. 1 #include<iostream> 2 #include<cstring& ...
- ACM Piggy Bank
Problem Description Before ACM can do anything, a budget must be prepared and the necessary financia ...
- ImageNet2017文件下载
ImageNet2017文件下载 文件说明 imagenet_object_localization.tar.gz包含训练集和验证集的图像数据和地面实况,以及测试集的图像数据. 图像注释以PASCAL ...
- ImageNet2017文件介绍及使用
ImageNet2017文件介绍及使用 文件说明 imagenet_object_localization.tar.gz包含训练集和验证集的图像数据和地面实况,以及测试集的图像数据. 图像注释以PAS ...
- Android开发训练之第五章第五节——Resolving Cloud Save Conflicts
Resolving Cloud Save Conflicts IN THIS DOCUMENT Get Notified of Conflicts Handle the Simple Cases De ...
随机推荐
- Exif的Orientation信息说明
EXIF Orientation 参数让你随便照像但都可以看到正确方向的照片而无需手动旋转(前提要图片浏览器支持,Windows 自带的不支持) 这个参数在佳能.尼康相机照的照片是自带的,但我的奥林巴 ...
- 纯JS省市区三级联动
代码下载
- EL表达式中获取list长度
在jsp页面中不能通过${list.size}取列表长度,而是 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" pref ...
- SDK(SoftWare Development Kit)介绍
ctrl+alt+shift+s进入项目设置页面: SKDs的界面可以设置SDK. 点击到project 可以为project选择sdk 如上图标注 1 所示,IntelliJ IDEA 支持 6 种 ...
- zoj1530 bfs
//Accepted zoj1530 270ms 40008KB #include <cstdio> #include <cstring> #include <iostr ...
- HDU 3829 - Cat VS Dog (二分图最大独立集)
题意:动物园有n只猫和m条狗,现在有p个小孩,他们有的喜欢猫,有的喜欢狗,其中喜欢猫的一定不喜欢狗,喜欢狗的一定不喜欢猫.现在管理员要从动物园中移除一些动物,如果一个小孩喜欢的动物留了下来而不喜欢的动 ...
- GSM cell phone calls use outdated encryption that can now be cracked with rainbow tables on a PC
Decrypting GSM phone calls Motivation. GSM telephony is the world’s most popular communication techn ...
- 官方文档学习之《start developing iOS apps(swift)》
1. let 关键字是用来定义常量的,任何类型的常量都可以进行定义:例如:定义字符串 let constantValue1 = "this is a string",也可以定义数 ...
- 转发:在开发机上绕过Chrome同源策略的办法
在开发机上绕过Chrome同源策略的办法 标签: Chrome同源策略跨域 2013-08-21 18:33 4399人阅读 评论(0) 收藏 举报 分类: Chrome扩展(1) 版权声明:本文为博 ...
- linux常用命令:1文件处理命令
文件处理命令 1.命令格式 命令格式:命令 [-选项] [参数] 例:ls -la /etc 说明:1)个别命令使用不遵循此格式 2)档有多个选项时,可以写在一起 3)简化选项与完整选项 2.目录 ...