POJ 1252 Euro Efficiency
背包 要么 BFS
意大利是说给你几个基本的货币,组成 1~100 所有货币,使用基本上的货币量以最小的。
出口 用法概率。和最大使用量。
能够BFS 有可能 。
只是记得数组开大点。 可能会出现 100 = 99+99 -98 的情况。
背包是先做一个全然背包,求得最少可能由多少相加。
然后做一个 01背包,看是否能被 减。
背包:
#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<stack>
#include<iostream>
#include<list>
#include<set>
#include<cmath>
#define INF 0x7fffffff
#define eps 1e-6
#define LL long long
using namespace std;
int dp[10002]; int value[7]; int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int m=10001;
for(int i=0; i<6; i++)
scanf("%d",&value[i]);
for(int i=1; i<m; i++)
dp[i]=10001;
dp[0]=0;
for(int i=0; i<6; i++)
{
for(int j=value[i]; j+value[i]<m; j++)
{
dp[j]=min(dp[j-value[i]]+1,dp[j]);
// printf("%d :%d==\n",j,dp[j]);
} } for(int i=0; i<6; i++)
{
for(int j=m-value[i]; j>0; j--)
{
dp[j]=min(dp[j+value[i]]+1,dp[j]);
// printf("%d :%d==\n",j,dp[j]);
} } double ans=0;
int maxn=0;
for(int i=1; i<=100; i++)
{
// printf("%d : %d\n",i,dp[i]);
ans+=dp[i];
maxn=max(maxn,dp[i]);
}
printf("%.2f %d\n",ans/100.0,maxn);
}
}
BFS:
#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<stack>
#include<iostream>
#include<list>
#include<set>
#include<cmath>
#define INF 0x7fffffff
#define eps 1e-6
#define LL long long
using namespace std;
struct lx
{
int ans,lv;
};
int ans[2051];
int value[7];
void bfs()
{
queue<lx>q;
bool vis[2051];
memset(vis,0,sizeof(vis));
lx now,tmp;
tmp.ans=0,tmp.lv=0;
q.push(tmp);
vis[0]=1;
while(!q.empty())
{
tmp=q.front();q.pop();
ans[tmp.ans]=tmp.lv;
for(int i=0;i<6;i++)
{
int num1=tmp.ans+value[i];
int num2=tmp.ans-value[i];
now.lv=tmp.lv+1;
if(!vis[num1]&&num1>0&&num1<2000)
{
vis[num1]=1;
now.ans=num1;
q.push(now);
}
if(!vis[num2]&&num2>0&&num2<2000)
{
vis[num2]=1;
now.ans=num2;
q.push(now);
}
}
}
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
for(int i=0; i<6; i++)
scanf("%d",&value[i]); bfs();
double an=0;
int maxn=0;
for(int i=1;i<=100;i++)
{
an+=ans[i];
maxn=max(maxn,ans[i]);
// printf("%d : %d\n",i,ans[i]);
}
printf("%.2f %d\n",an/100,maxn);
}
}
版权声明:本文博客原创文章。博客,未经同意,不得转载。
POJ 1252 Euro Efficiency的更多相关文章
- POJ 1252 Euro Efficiency(完全背包, 找零问题, 二次DP)
Description On January 1st 2002, The Netherlands, and several other European countries abandoned the ...
- POJ 1252 Euro Efficiency(最短路 完全背包)
题意: 给定6个硬币的币值, 问组成1~100这些数最少要几个硬币, 比如给定1 2 5 10 20 50, 组成40 可以是 20 + 20, 也可以是 50 -10, 最少硬币是2个. 分析: 这 ...
- POJ 1252 Euro Efficiency ( 完全背包变形 && 物品重量为负 )
题意 : 给出 6 枚硬币的面值,然后要求求出对于 1~100 要用所给硬币凑出这 100 个面值且要求所用的硬币数都是最少的,问你最后使用硬币的平均个数以及对于单个面值所用硬币的最大数. 分析 : ...
- POJ Euro Efficiency 1252
Euro Efficiency Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4109 Accepted: 1754 D ...
- Euro Efficiency(完全背包)
Euro Efficiency Time Limit : 2000/1000ms (Java/Other) Memory Limit : 20000/10000K (Java/Other) Tot ...
- POJ 1252 DP
题意:给你6个数.让你求出1~100范围内的数 最优情况下由这六个数加减几步得到. 输出平均值和最大值. 思路: 我就随便写了写,,,感觉自己的思路完全不对. 但是交上去 AC了!!! 我先当减法 不 ...
- POJ 3260 The Fewest Coins(多重背包+全然背包)
POJ 3260 The Fewest Coins(多重背包+全然背包) http://poj.org/problem?id=3260 题意: John要去买价值为m的商品. 如今的货币系统有n种货币 ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
- (转)POJ题目分类
初期:一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. ...
随机推荐
- 第五章_JSTL
5.1.下载JSTL http://jstl.java.net 5.2.JSTL类库 类别 下属功能 URI 前缀 Core 变量支持 http://java.sun.com/jsp/jstl/cor ...
- oracle一个用户密码管理多达同意三次企图登录
假设一个用户登录连续失败三次.两日,锁定用户,两天后再次登录的用户的能力. 创建profile文件: 更新账户: 三次登录失败后用户就会被锁定: 用户锁住之后要怎么给他解锁: 解锁之后就能够正常登录了 ...
- ASP.NET MVC源码分析
MVC4 源码分析(Visual studio 2012/2013) HttpModule中重要的UrlRoutingModule 9:this.OnApplicationPostResolveReq ...
- 03.Msbuild
MSBuild的深入认识 分类: 专题开发 自动化 2009-01-20 11:56 5711人阅读 评论(1) 收藏 举报 任务引擎脚本工作扩展build 最近在从事自动构造工作的过程中,对MSBu ...
- js控制图片缩放、水平和垂直方向居中对齐
已測试兼容 IE6,IE7,IE8,火狐FF,谷歌chrome. 这里使用了jquery插件,假设你不使用jquery,略微改造一下也非常快. 网上查了些资料,用css控制兼容性不好,看去非常揪心.于 ...
- [文学阅读] METEOR: An Automatic Metric for MT Evaluation with Improved Correlation with Human Judgments
METEOR: An Automatic Metric for MT Evaluation with Improved Correlation with Human Judgments Satanje ...
- effective c++ 条款12 copy all parts of an object
这经常发生在更改代码的时候,当有自己的copy 赋值函数或者copy 构造函数时,编译器就不会维护这两个函数.导致发生遗忘. 可能出现的场景 class Customer { private: std ...
- effective c++ 条款5 c++ 默默实现的函数
当写一个空类c++ 会为我们自动提供四个函数 1 默认构造函数 2 默认析构函数 3 拷贝构造函数 4 默认赋值运算符
- HIPO图
HIPO图(Hierarchy Plus Input/Processing/Output)是表示软件结构的一种图形工具.以模块分解的层次性以及模块内部输入.处理.输出三大基本部分为基础建立的.它由两部 ...
- 乐在其中设计模式(C#) - 外观模式(Facade Pattern)
原文:乐在其中设计模式(C#) - 外观模式(Facade Pattern) [索引页][源码下载] 乐在其中设计模式(C#) - 外观模式(Facade Pattern) 作者:webabcd 介绍 ...