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 ...
随机推荐
- 合理利用 vs2013的性能分析跟诊断
选择对应的项目==> 我正常是选择采样 就包括里面的一些耗时. 挺好用的. 可以根据热路径 还有访问的占比.知道哪个环节占用的访问时间 还有性能耗能多. 可以点进去 跟踪跟修改
- scst使用的一些问题
1,编译问题 问题描述: [root@localhost scstadmin]# make cd scstadmin && make all ]: Entering directory ...
- poj2264 dp+路径
//Accepted 208K 0MS //dp //最长公共子序列+路径 #include <cstdio> #include <cstring> #include < ...
- jQuery 关于 end() 方法的详细解释
<ul class="first"> <li class="foo">list item 1</li> <li> ...
- Oge中Mesh的渲染流程详述
转自:http://blog.csdn.net/yanonsoftware/article/details/1041396 首先一个Entity对象必须Attach到一个SceneNode. 1.创建 ...
- spark与Hadoop区别
2分钟读懂Hadoop和Spark的异同 2016.01.25 11:15:59 来源:51cto作者:51cto ( 0 条评论 ) 谈到大数据,相信大家对Hadoop和Apache Spark ...
- SVG 2D入门6 - 坐标与变换
坐标系统 SVG存在两套坐标系统:视窗坐标系与用户坐标系.默认情况下,用户坐标系与视窗坐标系的点是一一对应的,都为原点在视窗的左上角,x轴水平向右,y轴竖直向下:如下图所示: SVG的视窗位置一般是由 ...
- 强引用strong和弱引用weak的定义
1.强引用表示从属关系,引用对象拥有被引用的对象.弱引用则暗示引用对象不拥有被引用的对象.一个对象的寿命是由它被强引用多少次来决定的.只要对象还存在强引用,就不会释放该对象. 注意:但是对象之间的引用 ...
- How many instances created in the WebContainer
When the Servlet container starts, it: reads web.xml; finds the declared Servlets in the classpath; ...
- html网页标题
HTML代码 <html> <head> <!--<title>定义网页标题,显示在浏览器的标题--> <title>网页标题</ti ...